godot-csharp-vscode icon indicating copy to clipboard operation
godot-csharp-vscode copied to clipboard

Only attach works with Godot 4.0

Open markdibarry opened this issue 3 years ago • 4 comments

OS/device including version: Windows 10

Issue description: You can attach to a running instance, but Play in Editor, Launch, and Launch (Select Scene). Do not work. Unexpectedly, Launch tries to build and run the current scene open in the editor, and crashes. I only noticed due to some _Ready() GD.Print() method calls printing from the current scene.

markdibarry avatar Feb 14 '22 23:02 markdibarry

This extension was developed for Godot 3.x. It's likely that Godot 4.0's breaking changes made it incompatible with this extension and needs to be updated to support it.

I don't think it'd be very useful to start doing that work now since Godot 4.0 is still in alpha and the C# module is in the process of being ported to .NET 6.0.

By the way, Play in Editor and Launch just execute the Godot binary with some arguments (see https://docs.godotengine.org/en/latest/tutorials/editor/command_line_tutorial.html#command-line-reference).

raulsntos avatar Feb 14 '22 23:02 raulsntos

All good points. If that's all there is to Launch and Play in Editor I'm confused why it'd try to run the currently open scene. Attach still works, and for the most part, if I'm trying to debug a scene and hit F5 fast enough I can get it to attach before it crashes, so I thought there was a chance that maybe another launch mode wouldn't be that far off, so was worth reporting. Obviously no official mono builds are released, but there are always the few like me who do custom builds to still be able to contribute bug tickets and PRs. If a separate extension is planned, rather than to work on compatibility for this one, it'd probably be a quick solution then to update the ReadMe to mention that, so further 4.0 bugs can be closed.

markdibarry avatar Feb 14 '22 23:02 markdibarry

Just want to clarify that it should be opening the main scene, not the currently open the scene.

There could be a number of things changed in 4.0 that broke the extension, off the top of my head I remember the .mono folder was moved to .godot/mono where we store a metadata file with the port that the extension needs to attach the debugger so maybe that's what's causing the issue.

This metadata file is used by the Play in Editor mode and the path to the metadata file is set in:

https://github.com/godotengine/godot-csharp-vscode/blob/aedd1af0aecd042c2e196626ece7471983ed3066/src/godot-tools-messaging/client.ts#L228

This should be replaced in 4.0 with:

this.projectMetadataDir = path.join(godotProjectDir, '.godot', 'mono', 'metadata');

As for Launch mode, it seems commit https://github.com/godotengine/godot/pull/37099/commits/d79e28c3021a4410f41a3bbff111d56b28f155ef broke it because the --remote-debug argument now must start with the protocol tcp:// which we don't include in:

https://github.com/godotengine/godot-csharp-vscode/blob/aedd1af0aecd042c2e196626ece7471983ed3066/GodotDebugSession/GodotDebuggerSession.cs#L97

To fix it for 4.0 it should be replaced with something like:

"--remote-debug", $"tcp://{host}:{remoteDebugPort}", 

Of course, making these changes would make it work for 4.0 but would break the extension for 3.x, if you need it you can make these changes and build the extension yourself and it should work for your 4.0 projects. As for this extensions, I don't think there are plans to create a separate extension for 4.0, I think detecting the Godot version or adding a configuration option would be good enough.

raulsntos avatar Feb 15 '22 01:02 raulsntos

You were absolutely right. I created .mono/metadata directories in my project root and a ide_messaging_meta.txt with the same port number as the other one and Play in Editor now works. I'll try the changes you provided above. Seems like a pretty easy extra step to get things going in 4.0

Thanks!

Edit: I think that a configuration setting would be sufficient.

markdibarry avatar Feb 15 '22 02:02 markdibarry

As the merge to .NET 6 has happened, this is irrelevant.

markdibarry avatar Aug 30 '22 16:08 markdibarry