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

Loading GDExtensions fails on first run when .godot/extension_list.cfg is not generated yet #53163

Closed
akien-mga opened this issue Sep 28, 2021 · 5 comments

Comments

@akien-mga
Copy link
Member

Godot version

4.0.dev (4735a03)

System information

Linux, Mageia 9 x86_64

Issue description

When running a project using a GDExtension while the .godot/extension_list.cfg file doesn't exist yet, or hasn't been updated for a new extension, the editor will throw errors, such as:

SCRIPT ERROR: Parse Error: "Example" was not found in the current scope.
          at: GDScript::reload (res://main.gd:9)
ERROR: Method/function failed. Returning: ERR_PARSE_ERROR
   at: reload (modules/gdscript/gdscript.cpp:855)
ERROR: Condition "p_level <= int32_t(level_initialized)" is true.
   at: initialize_library (core/extension/native_extension.cpp:299)
SCRIPT ERROR: Parse Error: "Example" was not found in the current scope.
          at: GDScript::reload (res://main.gd:9)
ERROR: Method/function failed. Returning: ERR_PARSE_ERROR
   at: reload (modules/gdscript/gdscript.cpp:855)
ERROR: Cannot get class 'Example'.
   at: is_class_enabled (core/object/class_db.cpp:1538)
WARNING: Node Example of type Example cannot be created. A placeholder will be created instead.
     at: instantiate (scene/resources/packed_scene.cpp:164)
ERROR: In Object of type 'Node': Attempt to connect nonexistent signal 'custom_signal' to callable 'Node(main.gd)::_on_Example_custom_signal'.
   at: connect (core/object/object.cpp:1328)

Then the .godot/extension_list.cfg is properly generated and used successfully on subsequent edits, but this first use bug is annoying.

Steps to reproduce

Minimal reproduction project

https://github.com/godotengine/godot-cpp/tree/master/test/demo

@mhilbrunner
Copy link
Member

mhilbrunner commented Jan 20, 2022

Note: mkdir .godot and copying the extension_list.cfg in there before the first open seems to work as a workaround without any adverse effects, which is useful to get this to build on CI.

Still an annoying issue. :)

The code seems to be aware of the issue:

if (_scan_extensions()) {
//needs editor restart
//extensions also may provide filetypes to be imported, so they must run before importing
if (EditorNode::immediate_confirmation_dialog(TTR("Some extensions need the editor to restart to take effect."), first_scan ? TTR("Restart") : TTR("Save&Restart"), TTR("Continue"))) {
if (!first_scan) {
EditorNode::get_singleton()->save_all_scenes();
}
EditorNode::get_singleton()->restart_editor();
//do not import
return true;
}
}

However, I could not get this popup to trigger in my testing. This also seems quite hacky.

What I figure may be happening is that in the editor's file system scanning, code files are scanned first (which leads to the editor trying to compile them), and that then errors if the extensions are missing because thes code is referencing them and thus stuff that's not (yet) available.

Maybe we can make sure extensions are loaded and initialized before any other imports or the first editor file system scan.

@mhilbrunner
Copy link
Member

mhilbrunner commented Jan 20, 2022

By BastiaanOlij on RC:

At startup godot only loads what is added to the gdextension config file in your .import folder and the first time your library isn’t there.
Than later on the editor will scan for new extensions and add them, it does this everytime godot gets focus i think. At this time loading of the extension fails because there is a failsafe to ensure class types are loaded in order, and the order is set to the last type when extensions were originally processed.
Not sure what to do about it though

@BastiaanOlij
Copy link
Contributor

Ah yes, the folder is now called .godot and the file I was thinking about is extension_list.cfg. I was typing that on my phone so was remembering the old names :)

I see two potential options here:

  1. perform the initial scan for new extensions right after we load the extension_list.cfg when using the editor build, so something like:
load_extension_list()
#ifdef TOOLS_ENABLED
    scan_extensions()
#endif
  1. remove the failsafe so libraries don't fail when loaded after the editor is already loaded, I really don't get its purpose to be honest and it will allow you to copy extension into your new project and have them load right away.

@KoBeWi KoBeWi moved this to To Assess in 4.x Priority Issues May 26, 2022
@KoBeWi KoBeWi moved this from To Assess to Todo in 4.x Priority Issues May 26, 2022
@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 27, 2023
@YuriSizov
Copy link
Contributor

YuriSizov commented Jun 22, 2023

Is this still an issue? @akien-mga @BastiaanOlij @dsnopek

@dsnopek
Copy link
Contributor

dsnopek commented Jun 22, 2023

I've never personally encountered this issue.

I just tried to reproduce it by deleting the .godot/extension_list.cfg file in a project that uses a GDExtension, and then opening it in the editor. Everything appeared to load up fine, including the default scene which used nodes from the GDExtension. Looking on the console I didn't see any unexpected errors.

So, unless I'm missing a reproduction step, I think it's not an issue anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

5 participants