and3rson / foreigner

FFI library for Godot, built with GDNative
MIT License
25 stars 4 forks source link

FYI: Due to bug Foreigner is broken when built against `godot-cpp` 3.2 branch #10

Open follower opened 4 years ago

follower commented 4 years ago

Need to document this further but due to a bug/incompatibility between Godot 3.2 & godot-cpp when using Ref<>, Foreigner is broken when built against godot-cpp 3.2 branch.

The good news is that when Foreigner is built against the godot-cpp 3.1 branch it will run happily under Godot 3.2.

(Note: Improvements in godot-cpp 3.2 branch don't get backported to 3.1 branch though, so that may lead to issues.)

Related links:

(Interestingly, you can see the Destroying ForeignLibrary message from the destructor just before the crash. :) )

follower commented 4 years ago

An update on this: thanks to some godot-cpp bug fixes it seems Foreigner now builds successfully with https://github.com/godotengine/godot-cpp/commit/9eceb16f0553884094d0f659461649be5d333866 (see: https://github.com/godotengine/godot-cpp/issues/417 for some details).

The issues that seem to be fixed are Ref<>-related and memory leak related--which it turned out AFAICT were from the PoolStringArray of argument types supplied to the define() function.

An alternative workaround once I discovered the source of the memory leak, was to change to using an Array of variants and extracting the strings--which is still presumably an option for 3.1.

As mentioned in the issue linked above, the Ref fix does require that the __internal_constructor() direct call workaround is removed otherwise there's not enough references to keep things alive and Bad Things(TM) happen. I haven't committed these changes yet.

The only downside is that I don't think the changes have been backported to the godot-cpp 3.1 branch, and building against godot-cpp 3.2 branch seems to prevent the library working with Godot 3.1x, so in order to have Godot 3.1 support would require modification backporting.