Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export plugin not working with GdExtensions #80593

Closed
piiertho opened this issue Aug 13, 2023 · 2 comments · Fixed by #80999
Closed

Export plugin not working with GdExtensions #80593

piiertho opened this issue Aug 13, 2023 · 2 comments · Fixed by #80999

Comments

@piiertho
Copy link
Contributor

piiertho commented Aug 13, 2023

Godot version

4.1.1-stable

System information

macOS 13.4.1 arm64

Issue description

Implementing _export_file, _export_begin and _export_end in a gdextension export plugin does nothing.
In engine we have this code:

EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_platform, const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
	HashSet<String> features = p_platform.get_features(p_preset, p_debug);
	Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
	//initial export plugin callback
	for (int i = 0; i < export_plugins.size(); i++) {
		export_plugins.write[i]->set_export_preset(p_preset);
		if (export_plugins[i]->get_script_instance()) { //script based
			PackedStringArray features_psa;
			for (const String &feature : features) {
				features_psa.push_back(feature);
			}
			export_plugins.write[i]->_export_begin_script(features_psa, p_debug, p_path, p_flags);
		} else {
			export_plugins.write[i]->_export_begin(features, p_debug, p_path, p_flags);
		}
	}
}

We can see it will call _export_begin_script if a script instance is attached to the export plugin, otherwise it calls _export_begin. _export_begin_script does a GDVIRTUAL_CALL call, so it works within a script language. On another side _export_begin rely on classic cpp virtual call.
In the GdExtension case, we have no script instance attached, so we end up in classic cpp vtable case, but gdextensions does not use cpp vtable for inheritance. This ends up with no call to gdextension implementation.

Currently, the only work around to make a gdextension export plugin work is to create a script proxy for it, here is my example.
gdextension:

namespace godot {
    class FmodEditorExportPlugin : public EditorExportPlugin {
        GDCLASS(FmodEditorExportPlugin, EditorExportPlugin)

    public:
        void _export_begin(const PackedStringArray &features, bool is_debug, const String &path, uint32_t flags) override;
        void _export_file(const String& path, const String& type, const PackedStringArray& features) override;

        String _get_name() const override;

        static void _bind_methods();

        FmodEditorExportPlugin() = default;
        ~FmodEditorExportPlugin() = default;
    };
}

Proxy script:

@tool
class_name FmodEditorExportPluginProxy
extends FmodEditorExportPlugin

I think we should always rely on GDVIRTUAL_CALL and avoid check on script instance, so that both script and gdextensions are handled.

Steps to reproduce

Create a gdextension export plugin and add it using editor plugin.

Minimal reproduction project

N/A

alessandrofama added a commit to alessandrofama/wwise-godot-integration that referenced this issue Aug 16, 2023
This commit updates the wwise.gd addon script, wrapping up the integration of recent codebase changes by removing the ported plugins from GDScript.

Currently, the only editor plugin still added to the Editor via GDScript is the EditorExportPlugin. This will resolved as soon as a related bug (godotengine/godot#80593) is fixed.
alessandrofama added a commit to alessandrofama/wwise-godot-integration that referenced this issue Aug 16, 2023
This commit updates the wwise.gd addon script, wrapping up the integration of recent codebase changes by removing the ported plugins from GDScript.

Currently, the only editor plugin still added to the Editor via GDScript is the EditorExportPlugin. This will resolved as soon as a related bug (godotengine/godot#80593) is fixed.
@dsnopek
Copy link
Contributor

dsnopek commented Aug 25, 2023

@alessandrofama Thanks for reporting the bug and all your investigation!

If you have time to test if PR #80999 fixes the issue for you, that would be much appreciated :-)

@dsnopek
Copy link
Contributor

dsnopek commented Aug 26, 2023

Here's an MRP that I made to test the linked PR: gdext-editor-plugin-test.zip

@akien-mga akien-mga added this to the 4.2 milestone Aug 28, 2023
alessandrofama added a commit to alessandrofama/wwise-godot-integration that referenced this issue Aug 30, 2023
This commit updates the wwise.gd addon script, wrapping up the integration of recent codebase changes by removing the ported plugins from GDScript.

Currently, the only editor plugin still added to the Editor via GDScript is the EditorExportPlugin. This will resolved as soon as a related bug (godotengine/godot#80593) is fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants