Godot version
Godot 4 11e1c83
System information
Windows 10 64 bits NVIDIA GeForce GTX 1060
Issue description
Something happened in GDScript during the last weeks or so, such that now everytime I open and close my project, Godot crashes when unregistering the GDScript module. That wasn't happening before. This crash is visible when debugging Godot on Windows, using the debug runtime (which Godot is still not doing in debug builds). At the very least, it is inconvenient because it crashes on exit everytime, which disrupts debugging sessions. It appears to not reproduce without running Godot that way, but that might just be luck.
Here is the error:
Exception thrown at 0x00007FF6B55C4960 in godot.windows.editor.dev.x86_64.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
Exception thrown at 0x00007FFFB409CD29 in godot.windows.editor.dev.x86_64.exe: Microsoft C++ exception: std::__non_rtti_object at memory location 0x000000092DBFED18.
And the call stack, always the same:
issue_debug_notification(const wchar_t * const message) Line 28 (c:\Users\Marc\AppData\Local\Programs\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\internal\report_runtime_error.cpp:28)
__acrt_report_runtime_error(const wchar_t * message) Line 154 (c:\Users\Marc\AppData\Local\Programs\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\internal\report_runtime_error.cpp:154)
abort() Line 61 (c:\Users\Marc\AppData\Local\Programs\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:61)
terminate() Line 59 (c:\Users\Marc\AppData\Local\Programs\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\misc\terminate.cpp:59)
FindHandler<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, unsigned char recursive, int CatchDepth, unsigned __int64 * pMarkerRN) Line 781 (d:\a01\_work\12\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:781)
__InternalCxxFrameHandler<__FrameHandler4>(EHExceptionRecord * pExcept, unsigned __int64 * pRN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC, FH4::FuncInfo4 * pFuncInfo, int CatchDepth, unsigned __int64 * pMarkerRN, unsigned char recursive) Line 355 (d:\a01\_work\12\s\src\vctools\crt\vcruntime\src\eh\frame.cpp:355)
__CxxFrameHandler4(EHExceptionRecord * pExcept, unsigned __int64 RN, _CONTEXT * pContext, _xDISPATCHER_CONTEXT * pDC) Line 304 (d:\a01\_work\12\s\src\vctools\crt\vcruntime\src\eh\risctrnsctrl.cpp:304)
ntdll.dll!00007fffb66b241f() (Unknown Source:0)
ntdll.dll!00007fffb66614a4() (Unknown Source:0)
ntdll.dll!00007fffb66b0f4e() (Unknown Source:0)
KernelBase.dll!00007fffb409cd29() (Unknown Source:0)
_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 75 (d:\a01\_work\12\s\src\vctools\crt\vcruntime\src\eh\throw.cpp:75)
__RTDynamicCast(void * inptr, long VfDelta, void * srcVoid, void * targetVoid, int isReference) Line 291 (d:\a01\_work\12\s\src\vctools\crt\vcruntime\src\eh\rtti.cpp:291)
Object::cast_to<GDScript>(Object * p_object) Line 751 (godot4_fork\core\object\object.h:751)
GDScript::_get_gdscript_from_variant(const Variant & p_variant) Line 1296 (godot4_fork\modules\gdscript\gdscript.cpp:1296)
GDScript::_get_dependencies(RBSet<GDScript *,Comparator<GDScript *>,DefaultAllocator> & p_dependencies, const GDScript * p_except) Line 1309 (godot4_fork\modules\gdscript\gdscript.cpp:1309)
GDScript::get_dependencies() Line 1156 (godot4_fork\modules\gdscript\gdscript.cpp:1156)
GDScript::get_inverted_dependencies() Line 1180 (godot4_fork\modules\gdscript\gdscript.cpp:1180)
GDScript::get_must_clear_dependencies() Line 1195 (godot4_fork\modules\gdscript\gdscript.cpp:1195)
GDScript::clear() Line 1413 (godot4_fork\modules\gdscript\gdscript.cpp:1413)
GDScript::~GDScript() Line 1480 (godot4_fork\modules\gdscript\gdscript.cpp:1480)
GDScript::`scalar deleting destructor'(unsigned int) (Unknown Source:0)
memdelete<GDScript>(GDScript * p_class) Line 112 (godot4_fork\core\os\memory.h:112)
Ref<GDScript>::unref() Line 223 (godot4_fork\core\object\ref_counted.h:223)
Ref<GDScript>::~Ref<GDScript>() Line 233 (godot4_fork\core\object\ref_counted.h:233)
KeyValue<String,Ref<GDScript>>::~KeyValue<String,Ref<GDScript>>() (Unknown Source:0)
HashMapElement<String,Ref<GDScript>>::~HashMapElement<String,Ref<GDScript>>() (Unknown Source:0)
HashMapElement<String,Ref<GDScript>>::`scalar deleting destructor'(unsigned int) (Unknown Source:0)
memdelete<HashMapElement<String,Ref<GDScript>>>(HashMapElement<String,Ref<GDScript>> * p_class) Line 112 (godot4_fork\core\os\memory.h:112)
DefaultTypedAllocator<HashMapElement<String,Ref<GDScript>>>::delete_allocation(HashMapElement<String,Ref<GDScript>> * p_allocation) Line 206 (godot4_fork\core\os\memory.h:206)
HashMap<String,Ref<GDScript>,HashMapHasherDefault,HashMapComparatorDefault<String>,DefaultTypedAllocator<HashMapElement<String,Ref<GDScript>>>>::clear() Line 266 (godot4_fork\core\templates\hash_map.h:266)
GDScriptCache::~GDScriptCache() Line 400 (godot4_fork\modules\gdscript\gdscript_cache.cpp:400)
GDScriptCache::`scalar deleting destructor'(unsigned int) (Unknown Source:0)
memdelete<GDScriptCache>(GDScriptCache * p_class) Line 112 (godot4_fork\core\os\memory.h:112)
uninitialize_gdscript_module(ModuleInitializationLevel p_level) Line 152 (godot4_fork\modules\gdscript\register_types.cpp:152)
uninitialize_modules(ModuleInitializationLevel p_level) Line 244 (godot4_fork\modules\register_module_types.gen.cpp:244)
Main::cleanup(bool p_force) Line 3343 (godot4_fork\main\main.cpp:3343)
widechar_main(int argc, wchar_t * * argv) Line 183 (godot4_fork\platform\windows\godot_windows.cpp:183)
_main() Line 203 (godot4_fork\platform\windows\godot_windows.cpp:203)
main(int argc, char * * argv) Line 217 (godot4_fork\platform\windows\godot_windows.cpp:217)
WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 231 (godot4_fork\platform\windows\godot_windows.cpp:231)
invoke_main() Line 107 (d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:107)
__scrt_common_main_seh() Line 288 (d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
__scrt_common_main() Line 331 (d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
WinMainCRTStartup(void * __formal) Line 17 (d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_winmain.cpp:17)
kernel32.dll!00007fffb64874b4() (Unknown Source:0)
ntdll.dll!00007fffb66626a1() (Unknown Source:0)
Steps to reproduce
Unfortunately this is a race condition, and I have no expertise in the GDScript module, so reproduction steps are far from clear. But I can give some details.
About the project:
- The project has no GDScript editor plugins
- Scenes and scripts use classes of a custom module, however I don't think it matters much
- It has no default scenes. The project opens on an empty scene by default.
- All it takes me to reproduce it is to open the project, and close it. Nothing else.
- However, the project is far from empty. It contains a bunch of testing stuff. Scripts, scenes, textures, models.
- Some of the scripts in the project have errors in them.
- The script editor has many scripts open from previous sessions, which are opening automatically when I open the project. I don't have to open the Script tab though.

About the Godot build:
Minimal reproduction project
I was unable to reproduce this in a simpler project. It's likely a race condition, so it's quite random to stumble on the right combination that makes the crash occur. It may also depends on having opened scripts in a previous session, so opening it for the first time might not work. Despite my efforts to describe the context, it's possible that it doesn't reproduce for you. However if you run Godot the same way I did, you might stumble on a project that does.
project.zip
I can confirm it still crashes when no debugger is attached. I was profiling Godot using Tracy: when I closed Godot, it LOOKS like it closes normally, but Tracy picked up the crash.

Godot version
Godot 4 11e1c83
System information
Windows 10 64 bits NVIDIA GeForce GTX 1060
Issue description
Something happened in GDScript during the last weeks or so, such that now everytime I open and close my project, Godot crashes when unregistering the GDScript module. That wasn't happening before. This crash is visible when debugging Godot on Windows, using the debug runtime (which Godot is still not doing in debug builds). At the very least, it is inconvenient because it crashes on exit everytime, which disrupts debugging sessions. It appears to not reproduce without running Godot that way, but that might just be luck.
Here is the error:
And the call stack, always the same:
Steps to reproduce
Unfortunately this is a race condition, and I have no expertise in the GDScript module, so reproduction steps are far from clear. But I can give some details.
About the project:
About the Godot build:
scons p=windows target=editor dev_build=yes warnings=all werror=yes -j4detect.pyfor Windows, as described in _DEBUG is not defined when compiling Godot in debug mode on Windows #31608thirdparty/oidn/core/device.cppin such a way that thethread_localinside is not created in global space. Just put it inside a static function that returns a reference to it.Minimal reproduction project
I was unable to reproduce this in a simpler project. It's likely a race condition, so it's quite random to stumble on the right combination that makes the crash occur. It may also depends on having opened scripts in a previous session, so opening it for the first time might not work. Despite my efforts to describe the context, it's possible that it doesn't reproduce for you. However if you run Godot the same way I did, you might stumble on a project that does.
project.zip
I can confirm it still crashes when no debugger is attached. I was profiling Godot using Tracy: when I closed Godot, it LOOKS like it closes normally, but Tracy picked up the crash.
