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

Use gdextension in the project, directly program crashed after starting the godot engine #81478

Open
BeyondXinXin opened this issue Sep 9, 2023 · 3 comments

Comments

@BeyondXinXin
Copy link

BeyondXinXin commented Sep 9, 2023

Godot version

4.1.1

System information

win

Issue description

Wrote a simple link library using GDExtension
After launching the game for the first time using the Godot engine, the engine crashes.

First time means: delete .goidot

However, after crashed, as long as it is not deleted .goidot.Everything is normal,library Work according to my expectations

image


I tried to compile godot4.1.1 by myself.
When I ran it for the first time, I got more detailed errors,.

Godot Engine v4.1.1.stable.custom_build.bd6af8e0e - https://godotengine.org
OpenGL API 3.3.0 NVIDIA 532.09 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce RTX 3050 Ti Laptop GPU

Editing project: F:/github/extension_test/game
Godot Engine v4.1.1.stable.custom_build.bd6af8e0e - https://godotengine.org
OpenGL API 3.3.0 NVIDIA 532.09 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce RTX 3050 Ti Laptop GPU

ERROR: Condition "!texture_allocs_cache.has(p_id)" is true.
   at: GLES3::Utilities::texture_free_data (F:\godot\drivers\gles3\storage\utilities.h:111)
ERROR: Cubemap Arrays are not supported in the GL Compatibility backend.
   at: (drivers\gles3\storage\texture_storage.cpp:763)
ERROR: Attempting to use an uninitialized RID
   at: (F:\godot\core/templates/rid_owner.h:199)
ERROR: Condition "!t" is true.
   at: GLES3::TextureStorage::texture_free (drivers\gles3\storage\texture_storage.cpp:705)
ERROR: FATAL: Condition "!exists" is true.
   at: HashMap<class StringName,int,struct HashMapHasherDefault,struct HashMapComparatorDefault<class StringName>,class DefaultTypedAllocator<struct HashMapElement<class StringName,int> > >::operator [] (F:\godot\core/templates/hash_map.h:504)

================================================================
CrashHandlerException: Program crashed
Engine version: Godot Engine v4.1.1.stable.custom_build (bd6af8e0ea69167dd0627f3bd54f9105bda0f8b5)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] HashMap<StringName,int,HashMapHasherDefault,HashMapComparatorDefault<StringName>,DefaultTypedAllocator<HashMapElement<StringName,int> > >::operator[] (F:\godot\core\templates\hash_map.h:504)
[1] HashMap<StringName,int,HashMapHasherDefault,HashMapComparatorDefault<StringName>,DefaultTypedAllocator<HashMapElement<StringName,int> > >::operator[] (F:\godot\core\templates\hash_map.h:504)
[2] GDScriptByteCodeGenerator::write_assign_with_conversion (F:\godot\modules\gdscript\gdscript_byte_codegen.cpp:889)
[3] GDScriptCompiler::_parse_function (F:\godot\modules\gdscript\gdscript_compiler.cpp:2234)
[4] GDScriptCompiler::_compile_class (F:\godot\modules\gdscript\gdscript_compiler.cpp:2802)
[5] GDScriptCompiler::compile (F:\godot\modules\gdscript\gdscript_compiler.cpp:2962)
[6] GDScript::reload (F:\godot\modules\gdscript\gdscript.cpp:787)
[7] GDScriptCache::get_full_script (F:\godot\modules\gdscript\gdscript_cache.cpp:307)
[8] ResourceFormatLoaderGDScript::load (F:\godot\modules\gdscript\gdscript.cpp:2701)
[9] ResourceLoader::_load (F:\godot\core\io\resource_loader.cpp:260)
[10] ResourceLoader::_thread_load_function (F:\godot\core\io\resource_loader.cpp:318)
[11] ResourceLoader::_load_start (F:\godot\core\io\resource_loader.cpp:498)
[12] ResourceLoader::load (F:\godot\core\io\resource_loader.cpp:414)
[13] EditorFileSystem::_update_script_classes (F:\godot\editor\editor_file_system.cpp:1592)
[14] EditorFileSystem::_update_pending_script_classes (F:\godot\editor\editor_file_system.cpp:1623)
[15] EditorFileSystem::reimport_files (F:\godot\editor\editor_file_system.cpp:2335)
[16] EditorFileSystem::_update_scan_actions (F:\godot\editor\editor_file_system.cpp:690)
[17] EditorFileSystem::_notification (F:\godot\editor\editor_file_system.cpp:1282)
[18] EditorFileSystem::_notificationv (F:\godot\editor\editor_file_system.h:146)
[19] Object::notification (F:\godot\core\object\object.cpp:798)
[20] SceneTree::_process_group (F:\godot\scene\main\scene_tree.cpp:949)
[21] SceneTree::_process (F:\godot\scene\main\scene_tree.cpp:1026)
[22] SceneTree::process (F:\godot\scene\main\scene_tree.cpp:510)
[23] Main::iteration (F:\godot\main\main.cpp:3425)
[24] OS_Windows::run (F:\godot\platform\windows\os_windows.cpp:1479)
[25] widechar_main (F:\godot\platform\windows\godot_windows.cpp:182)
[26] _main (F:\godot\platform\windows\godot_windows.cpp:204)
[27] main (F:\godot\platform\windows\godot_windows.cpp:218)
[28] WinMain (F:\godot\platform\windows\godot_windows.cpp:232)
[29] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[30] <couldn't map PC to fn name>
-- END OF BACKTRACE --
================================================================

Steps to reproduce

I follow the Static typing rules when writing scripts.

@onready var navigation_region: GridBasedNavigationRegion2D = $GridBasedNavigationRegion2D

I try to understand the loading logic of GDExtension briefly:
When I open the project from the project manager:

  1. If it exists .godot/extension_list.cfg
    GDExtensionManager will load the dll and register the class written by itself as NATIVE in GDscript.
  2. Compile all *.gd scripts.
  3. Find and parse the new *.gdextension resources.
  4. Again GDExtensionManager will load the dll and register the class written by itself as NATIVE in GDscript.

or

  1. Not present .godot/extension_list.cfg.
  2. Compile all *.gd scripts
  3. Find and parse all *.gdextension resources.
  4. FirstGDExtensionManager will load the dll and register the class written by itself as NATIVE in GDscript.

When the *.gd script is compiled without registration, the program crashes.

Repair method

When write_assign_with_conversion judging whether the type is registered
I don't know how to prompt the error properly.
Perhaps: Regardless of the existence of .godot/extension_list.cfg, all resources in *.gdextension should be parsed before starting to compile scripts.

image

void GDScriptByteCodeGenerator::write_assign_with_conversion(const Address &p_target, const Address &p_source) {
	switch (p_target.type.kind) {
		case GDScriptDataType::BUILTIN: {
                    ...
		} break;
		case GDScriptDataType::NATIVE: {
			if (!GDScriptLanguage::get_singleton()->get_global_map().has(p_target.type.native_type)) {
				ERR_PRINT(vformat(R"(Compiler Could not find type "%s" in the current scope.)", p_target.type.native_type));
				break;
			}
			int class_idx = GDScriptLanguage::get_singleton()->get_global_map()[p_target.type.native_type];
			Variant nc = GDScriptLanguage::get_singleton()->get_global_array()[class_idx];
			class_idx = get_constant_pos(nc) | (GDScriptFunction::ADDR_TYPE_CONSTANT << GDScriptFunction::ADDR_BITS);
			append_opcode(GDScriptFunction::OPCODE_ASSIGN_TYPED_NATIVE);
			append(p_target);
			append(p_source);
			append(class_idx);
		} break;

Minimal reproduction project

extension_test.zip

@bitsawer
Copy link
Member

bitsawer commented Sep 9, 2023

The issue description and CrashHandlerException stack trace look vaguely similar to #80850, but not sure how similar these issues are. Looks like Terrain3D gdextension implemented some changes to work around their problem: TokisanGames/Terrain3D#196

@capnm
Copy link
Contributor

capnm commented Sep 22, 2023

  • Not present .godot/extension_list.cfg.

I have similar issues with linux scons based GDExtensions. After clearing godot caches, the first editor launch crashes. Backing up the extension_list.cfg file and copying it back to the empty .godot directory fixes the crash issue.

See godotengine/godot-cpp#1249.

@GreenCrowDev
Copy link
Contributor

I tried this project with the latest 4.4.dev7 release.
No crashes, just a probably unrelated error:

ERROR: scene/main/node.cpp:1396 - Condition "name.is_empty()" is true.

Probably fixed by #92667

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

No branches or pull requests

5 participants