C#: Fix editor unable to play game after IDE PlayRequest
The editor wasn't clearing the debugger agent
settings properly after a processing a play
request from an IDE. This caused consequent play
attempts to fail if not launched from the IDE,
as the game would still attempt and fail to
connect to the debugger.
The concrete cause: Forgetting to clear the
`GODOT_MONO_DEBUGGER_AGENT` environment variable.
(cherry picked from commit 6e7da72648
)
This commit is contained in:
parent
f90931c47a
commit
c8845291c3
|
@ -205,23 +205,8 @@ namespace GodotTools
|
||||||
if (File.Exists(editorScriptsMetadataPath))
|
if (File.Exists(editorScriptsMetadataPath))
|
||||||
File.Copy(editorScriptsMetadataPath, playerScriptsMetadataPath);
|
File.Copy(editorScriptsMetadataPath, playerScriptsMetadataPath);
|
||||||
|
|
||||||
var currentPlayRequest = GodotSharpEditor.Instance.CurrentPlaySettings;
|
if (GodotSharpEditor.Instance.SkipBuildBeforePlaying)
|
||||||
|
|
||||||
if (currentPlayRequest != null)
|
|
||||||
{
|
|
||||||
if (currentPlayRequest.Value.HasDebugger)
|
|
||||||
{
|
|
||||||
// Set the environment variable that will tell the player to connect to the IDE debugger
|
|
||||||
// TODO: We should probably add a better way to do this
|
|
||||||
Environment.SetEnvironmentVariable("GODOT_MONO_DEBUGGER_AGENT",
|
|
||||||
"--debugger-agent=transport=dt_socket" +
|
|
||||||
$",address={currentPlayRequest.Value.DebuggerHost}:{currentPlayRequest.Value.DebuggerPort}" +
|
|
||||||
",server=n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!currentPlayRequest.Value.BuildBeforePlaying)
|
|
||||||
return true; // Requested play from an external editor/IDE which already built the project
|
return true; // Requested play from an external editor/IDE which already built the project
|
||||||
}
|
|
||||||
|
|
||||||
return BuildProjectBlocking("Debug");
|
return BuildProjectBlocking("Debug");
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace GodotTools
|
||||||
|
|
||||||
public BottomPanel BottomPanel { get; private set; }
|
public BottomPanel BottomPanel { get; private set; }
|
||||||
|
|
||||||
public PlaySettings? CurrentPlaySettings { get; set; }
|
public bool SkipBuildBeforePlaying { get; set; } = false;
|
||||||
|
|
||||||
public static string ProjectAssemblyName
|
public static string ProjectAssemblyName
|
||||||
{
|
{
|
||||||
|
|
|
@ -330,9 +330,10 @@ namespace GodotTools.Ides
|
||||||
{
|
{
|
||||||
DispatchToMainThread(() =>
|
DispatchToMainThread(() =>
|
||||||
{
|
{
|
||||||
GodotSharpEditor.Instance.CurrentPlaySettings = new PlaySettings();
|
// TODO: Add BuildBeforePlaying flag to PlayRequest
|
||||||
|
|
||||||
|
// Run the game
|
||||||
Internal.EditorRunPlay();
|
Internal.EditorRunPlay();
|
||||||
GodotSharpEditor.Instance.CurrentPlaySettings = null;
|
|
||||||
});
|
});
|
||||||
return Task.FromResult<Response>(new PlayResponse());
|
return Task.FromResult<Response>(new PlayResponse());
|
||||||
}
|
}
|
||||||
|
@ -341,10 +342,22 @@ namespace GodotTools.Ides
|
||||||
{
|
{
|
||||||
DispatchToMainThread(() =>
|
DispatchToMainThread(() =>
|
||||||
{
|
{
|
||||||
GodotSharpEditor.Instance.CurrentPlaySettings =
|
// Tell the build callback whether the editor already built the solution or not
|
||||||
new PlaySettings(request.DebuggerHost, request.DebuggerPort, request.BuildBeforePlaying ?? true);
|
GodotSharpEditor.Instance.SkipBuildBeforePlaying = !(request.BuildBeforePlaying ?? true);
|
||||||
|
|
||||||
|
// Pass the debugger agent settings to the player via an environment variables
|
||||||
|
// TODO: It would be better if this was an argument in EditorRunPlay instead
|
||||||
|
Environment.SetEnvironmentVariable("GODOT_MONO_DEBUGGER_AGENT",
|
||||||
|
"--debugger-agent=transport=dt_socket" +
|
||||||
|
$",address={request.DebuggerHost}:{request.DebuggerPort}" +
|
||||||
|
",server=n");
|
||||||
|
|
||||||
|
// Run the game
|
||||||
Internal.EditorRunPlay();
|
Internal.EditorRunPlay();
|
||||||
GodotSharpEditor.Instance.CurrentPlaySettings = null;
|
|
||||||
|
// Restore normal settings
|
||||||
|
Environment.SetEnvironmentVariable("GODOT_MONO_DEBUGGER_AGENT", "");
|
||||||
|
GodotSharpEditor.Instance.SkipBuildBeforePlaying = false;
|
||||||
});
|
});
|
||||||
return Task.FromResult<Response>(new DebugPlayResponse());
|
return Task.FromResult<Response>(new DebugPlayResponse());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue