godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Using scons in release, crash when initializing gdextension.

Open whileload opened this issue 2 months ago • 8 comments

Godot version

4.5

godot-cpp version

4.5

System information

Windows 10

Issue description

I used two compilers: msvc and llvm. Build via CMake works.

Possibly related. https://github.com/godotengine/godot/issues/64897 My comment there: https://github.com/godotengine/godot/issues/64897#issuecomment-3340480432

Steps to reproduce

scons platform=windows target=template_release

Even with an empty extension, where there is only an initialization function.

using namespace godot;

void initialize_gdextension_types(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}

}

void uninitialize_gdextension_types(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}
}

extern "C" {
// Initialization
GDExtensionBool GDE_EXPORT
resouls_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address,
		GDExtensionClassLibraryPtr p_library,
		GDExtensionInitialization *r_initialization) {
	GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library,
			r_initialization);
	init_obj.register_initializer(initialize_gdextension_types);
	init_obj.register_terminator(uninitialize_gdextension_types);
	init_obj.set_minimum_library_initialization_level(
			MODULE_INITIALIZATION_LEVEL_SCENE);

	// There is a crash in this function. 
	GDExtensionBool r = init_obj.init();


	return r;
}
}

Minimal reproduction project

N/A

whileload avatar Sep 27 '25 08:09 whileload

Thanks for the report!

When it crashes, I assume you're loading the GDExtension in a release build of Godot? Or, are you loading the release GDExtension in a debug version of Godot (like the editor)?

There are some known issues with mixing release and debug builds in Godot 4.5 and earlier, and it's recommended to only use release GDExtensions with release Godot, and debug GDExtensions with debug Godot.

Anyway, just wanted to quickly confirm if that was your issue, or something else

dsnopek avatar Oct 04 '25 19:10 dsnopek

Build via CMake works.

Makes me wish I finished automating my build flag comparison tool. @dsnopek if you think it worth while I can do some fresh analysis of the builds to make sure they're still in sync in terms of compile commands.

enetheru avatar Oct 04 '25 23:10 enetheru

@dsnopek if you think it worth while I can do some fresh analysis of the builds to make sure they're still in sync in terms of compile commands.

Sure, I think it would be worth checking! We don't test building with LLVM on Windows all that much, so I also wouldn't be surprised if our scons configuration does something weird in that case, although, the reporter says the issue happens with MSVC too

dsnopek avatar Oct 05 '25 10:10 dsnopek

@dsnopek there's still some cleaning to perform but this might help, I havent analysed the contents, I've just been playing around generating the thing from compile commands: https://gist.githubusercontent.com/enetheru/988acf531b70992d73ea523ab25de621/raw/96eb2729b377f806eab30dc3b000a0fd547b4f37/gistfile1.txt

enetheru avatar Oct 08 '25 10:10 enetheru

I've updated that link , should be more fun to look at now.

enetheru avatar Oct 09 '25 08:10 enetheru

can you share the build commands you use to build using cmake please?

enetheru avatar Oct 12 '25 14:10 enetheru

I've tested and could not replicate a crash.

  • Win11
  • both msvc, and clang-cl from visual studio 2022
  • using scons
  • integration testing project, and stripped down version copy and pasted from above.
  • official 4.5 editor, release and debug templates.

Granted I'm on Windows 11, so i dunno.

enetheru avatar Oct 18 '25 06:10 enetheru

Thanks for the report!

When it crashes, I assume you're loading the GDExtension in a release build of Godot? Or, are you loading the release GDExtension in a debug version of Godot (like the editor)?

There are some known issues with mixing release and debug builds in Godot 4.5 and earlier, and it's recommended to only use release GDExtensions with release Godot, and debug GDExtensions with debug Godot.

Anyway, just wanted to quickly confirm if that was your issue, or something else

Dude... Thanks for reporting this!

ernzo avatar Oct 22 '25 18:10 ernzo