Skip to content

Commit

Permalink
Code cleanup for the export logic
Browse files Browse the repository at this point in the history
Update the export logic so that export plugin objects are handed through references instead of using `memnew` and `memfree`
  • Loading branch information
nontoxicguy authored Jan 29, 2024
1 parent a780c4b commit e946c3a
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ void KhronosEditorPlugin::_bind_methods() {}

void KhronosEditorPlugin::_enter_tree() {
// Initialize the editor export plugin
khronos_export_plugin = memnew(KhronosEditorExportPlugin);
khronos_export_plugin.instantiate();
add_export_plugin(khronos_export_plugin);
}

void KhronosEditorPlugin::_exit_tree() {
// Clean up the editor export plugin
remove_export_plugin(khronos_export_plugin);

memfree(khronos_export_plugin);
khronos_export_plugin = nullptr;
khronos_export_plugin.unref();
}

KhronosEditorExportPlugin::KhronosEditorExportPlugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ class KhronosEditorPlugin : public EditorPlugin {
static void _bind_methods();

private:
KhronosEditorExportPlugin *khronos_export_plugin = nullptr;
Ref<KhronosEditorExportPlugin> khronos_export_plugin;
};
5 changes: 2 additions & 3 deletions godotopenxrlynx/src/main/cpp/export/lynx_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void LynxEditorPlugin::_bind_methods() {}

void LynxEditorPlugin::_enter_tree() {
// Initialize the editor export plugin
lynx_export_plugin = memnew(OpenXREditorExportPlugin);
lynx_export_plugin.instantiate();
lynx_export_plugin->set_vendor_name(LYNX_VENDOR_NAME);
add_export_plugin(lynx_export_plugin);
}
Expand All @@ -44,6 +44,5 @@ void LynxEditorPlugin::_exit_tree() {
// Clean up the editor export plugin
remove_export_plugin(lynx_export_plugin);

memfree(lynx_export_plugin);
lynx_export_plugin = nullptr;
lynx_export_plugin.unref();
}
2 changes: 1 addition & 1 deletion godotopenxrlynx/src/main/cpp/export/lynx_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ class LynxEditorPlugin : public EditorPlugin {
static void _bind_methods();

private:
OpenXREditorExportPlugin *lynx_export_plugin = nullptr;
Ref<OpenXREditorExportPlugin> lynx_export_plugin;
};
5 changes: 2 additions & 3 deletions godotopenxrmeta/src/main/cpp/export/meta_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ void MetaEditorPlugin::_bind_methods() {}

void MetaEditorPlugin::_enter_tree() {
// Initialize the editor export plugin
meta_export_plugin = memnew(MetaEditorExportPlugin);
meta_export_plugin.instantiate();
add_export_plugin(meta_export_plugin);
}

void MetaEditorPlugin::_exit_tree() {
// Clean up the editor export plugin
remove_export_plugin(meta_export_plugin);

memfree(meta_export_plugin);
meta_export_plugin = nullptr;
meta_export_plugin.unref();
}

MetaEditorExportPlugin::MetaEditorExportPlugin() {
Expand Down
3 changes: 1 addition & 2 deletions godotopenxrmeta/src/main/cpp/export/meta_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@ class MetaEditorPlugin : public EditorPlugin {
static void _bind_methods();

private:
MetaEditorExportPlugin *meta_export_plugin = nullptr;

Ref<MetaEditorExportPlugin> meta_export_plugin;
};
5 changes: 2 additions & 3 deletions godotopenxrpico/src/main/cpp/export/pico_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void PicoEditorPlugin::_bind_methods() {}

void PicoEditorPlugin::_enter_tree() {
// Initialize the editor export plugin
pico_export_plugin = memnew(OpenXREditorExportPlugin);
pico_export_plugin.instantiate();
pico_export_plugin->set_vendor_name(PICO_VENDOR_NAME);
add_export_plugin(pico_export_plugin);
}
Expand All @@ -44,6 +44,5 @@ void PicoEditorPlugin::_exit_tree() {
// Clean up the editor export plugin
remove_export_plugin(pico_export_plugin);

memfree(pico_export_plugin);
pico_export_plugin = nullptr;
pico_export_plugin.unref();
}
2 changes: 1 addition & 1 deletion godotopenxrpico/src/main/cpp/export/pico_export_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ class PicoEditorPlugin : public EditorPlugin {
static void _bind_methods();

private:
OpenXREditorExportPlugin *pico_export_plugin = nullptr;
Ref<OpenXREditorExportPlugin> pico_export_plugin;
};

0 comments on commit e946c3a

Please sign in to comment.