Closed ghost closed 7 months ago
Looking through the code, remove_export_plugin
only removes the entry from the list of plugins, it should not free the object.
The real issue here is that plugins should be handed through references, we shouldn't be using memnew
and memfree
to create these objects. The result thus is that on the removal of the plugin from the array, the refcount hits 0, and the object is freed. But that's a fluke, not something to rely on.
To properly fix this, OpenXREditorExportPlugin *pico_export_plugin = nullptr;
should become Ref<OpenXREditorExportPlugin>
, and we should use pico_export_plugin.instantiate()
and pico_export_plugin.unref()
to instantiate and free these objects.
Similar changes should be applied to the other plugins.
Expected due to my very limited knowledge of C++. Effectively the build still has the issue, making that pr permitted to test my changes. Thanks for your understanding, going to update this pr with your recommended changes.
I looked at the stack trace with gdb after reproducing #67 to see a double free error:
I've noticed that remove_export_plugin frees the export plugin meaning that the memfree called after is throwing the error.
I can't test it, but I'm almost sure this fixes the error. I haven't worked with C++ yet, first time.