Skip to content

2dog xUnit tests crash on godot engine start #22

@dvankley

Description

@dvankley

I'm running a custom build of Godot 4.6.2-stable on Mac OS Tahoe with .NET 8.

Running 2dog tests via dotnet test and Rider crash on Godot engine start.

I have analyzed and "fixed" this locally with AI, but I wanted to report the details to validate if these are actually the issues they appears to be (and if so, if I should create a corresponding issue(s) in the Godot repo) or if I'm just doing something dumb.

Issue 1: NSInternalInconsistencyException

On launch, Godot crashes with:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'API misuse: setting the main menu on a non-main thread. Main menu contents should only be modified from the main thread.'

This appears to be a MacOS AppKit error due to the xUnit process owning the main thread, a child thread that owns the Godot engine trying to do UI updates, and AppKit crashing on that violation.

The fix here was too move the --headless check earlier in the macos setup process so OS_MacOS_Headless could be created if --headless was passed in.

Issue 2: OS.has_feature("dotnet")

Godot only initializes .NET in non-tools builds when OS.has_feature("dotnet") is true at gd_mono.cpp (line 610). Normal C# export gets that from GodotTools _GetExportFeatures() at ExportPlugin.cs (line 30). The libgodot/xUnit path is not an export, so the feature is absent. This was the fix I used. This seems like there should probably be a simpler way.

Issue 3: hostfxr initialize

gd_mono.cpp (line 402) calls hostfxr_initialize_for_dotnet_command_line, which is for starting a new process rather than loading a .net component into an existing process.
I got around this by having 2dog pass an init function pointer and having godot accept it, which seems to fix the issue.

Conclusion

I'm not at all an SME in this stuff, so these fixes are almost entirely AI slop. Let me know what your thoughts are on next steps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions