maiself / godot-python-extension

Python language bindings for the Godot game engine
https://godot-python-extension.readthedocs.io
MIT License
24 stars 4 forks source link

Run problems on macOS #30

Closed Ivorforce closed 3 weeks ago

Ivorforce commented 3 weeks ago

First off, #26 needs to be merged.

It makes it compile, but it's not correct yet.

Patching the Executable

To get a compile that binds libpython3.12 correctly on launch, I have to modify the executable:

scons
install_name_tool -add_rpath @loader_path bin/macos-universal/libgodot-python.macos.universal.dylib
install_name_tool -change /install/lib/libpython3.12.dylib @rpath/libpython3.12.dylib bin/macos-universal/libgodot-python.macos.universal.dylib

This gets me far enough for Godot to load the dylib and it starting to execute code. After my research, I think rpaths are the correct way to handle library loading. These fixes should probably therefore be made part of the build process (though I'm not sure yet how).

Python nested error failure

Now the latest run attempt gets me this:

❯ /Applications/Godot.app/Contents/MacOS/Godot /Users/lukas/dev/godot/godot-python-extension/test/project.godot

================================================================
handle_crash: Program crashed with signal 4
Engine version: Godot Engine v4.3.stable.official (77dcf97d82cbfe4e4615475fa52ca03da645dbd8)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] 1   libsystem_platform.dylib            0x00007ff8020985ed _sigtramp + 29
[2] 2   ???                                 0x0000000000006e6f 0x0 + 28271
[3] pybind11::error_already_set::m_fetched_error_deleter(pybind11::detail::error_fetch_and_normalize*)
[4] 4   libgodot-python.macos.universal.dyl 0x0000000112000966 libgodot-python.macos.universal.dyl + 6502
[5] GDExtensionManager::initialize_extensions(GDExtension::InitializationLevel) (in Godot) + 59
[6] register_core_extensions() (in Godot) + 162
[7] Main::setup(char const*, int, char**, bool) (in Godot) + 16476
[8] main (in Godot) + 299
[9] 9   dyld                                0x00007ff801d10418 start + 1896
-- END OF BACKTRACE --
================================================================
zsh: abort      /Applications/Godot.app/Contents/MacOS/Godot

I think this happens because PyBind11 is trying to throw an error, but fails on dealloc (?). This happens early in initialize_python_module, I think.

Ivorforce commented 3 weeks ago

I figured it out; get_executable_path had no macOS implementation. The errors were just extremely misleading.