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

Lambda call within a non-main thread forces Godot to crash at exit #84190

Closed
Chaosus opened this issue Oct 30, 2023 · 5 comments · Fixed by #84659
Closed

Lambda call within a non-main thread forces Godot to crash at exit #84190

Chaosus opened this issue Oct 30, 2023 · 5 comments · Fixed by #84659

Comments

@Chaosus
Copy link
Member

Chaosus commented Oct 30, 2023

Godot version

9144457

System information

Windows 11

Issue description

Running the following code:

extends Node3D

var thread : Thread
var array = [3, 2, 1]

func _ready():
	thread = Thread.new()
	thread.start(do_some_work)
	thread.wait_to_finish()
	print(array)

func do_some_work() -> void:
	array.sort_custom(func(a, b): return a < b)

executes correctly, but when user closes the application or call get_tree().quit() the Godot will crash with the following call stack:

 	godot.windows.editor.x86_64.exe!GDScript::clear(GDScript::ClearData * p_clear_data) Line 1440	C++
 	godot.windows.editor.x86_64.exe!GDScript::~GDScript() Line 1518	C++
 	godot.windows.editor.x86_64.exe!GDScript::`scalar deleting destructor'(unsigned int)	C++
 	[Inline Frame] godot.windows.editor.x86_64.exe!memdelete(GDScript * p_class) Line 109	C++
 	godot.windows.editor.x86_64.exe!Ref<GDScript>::unref() Line 210	C++
 	[Inline Frame] godot.windows.editor.x86_64.exe!Ref<GDScript>::{dtor}() Line 222	C++
 	[Inline Frame] godot.windows.editor.x86_64.exe!memdelete(HashMapElement<String,Ref<GDScript>> *) Line 109	C++
 	[Inline Frame] godot.windows.editor.x86_64.exe!DefaultTypedAllocator<HashMapElement<String,Ref<GDScript>>>::delete_allocation(HashMapElement<String,Ref<GDScript>> * p_allocation) Line 206	C++
 	godot.windows.editor.x86_64.exe!HashMap<String,Ref<GDScript>,HashMapHasherDefault,HashMapComparatorDefault<String>,DefaultTypedAllocator<HashMapElement<String,Ref<GDScript>>>>::clear() Line 265	C++
 	godot.windows.editor.x86_64.exe!GDScriptCache::clear() Line 445	C++
>	godot.windows.editor.x86_64.exe!GDScriptLanguage::finish() Line 2116	C++
 	godot.windows.editor.x86_64.exe!ScriptServer::finish_languages() Line 229	C++
 	godot.windows.editor.x86_64.exe!Main::cleanup(bool p_force) Line 3763	C++
 	godot.windows.editor.x86_64.exe!widechar_main(int argc, wchar_t * * argv) Line 184	C++
 	godot.windows.editor.x86_64.exe!_main() Line 206	C++
 	godot.windows.editor.x86_64.exe!main(int argc, char * * argv) Line 218	C++
 	[Inline Frame] godot.windows.editor.x86_64.exe!invoke_main() Line 102	C++
 	godot.windows.editor.x86_64.exe!__scrt_common_main_seh() Line 288	C++
 	kernel32.dll!00007fff2373257d()	Unknown
 	ntdll.dll!00007fff2540aa78()	Unknown

изображение

Seems like a desynced mutex, or corrupted heap. Maybe this is a duplicate of #84046, but I'm not sure.

Steps to reproduce

Run the script printed above, and after then try to close the game application.

Minimal reproduction project

TestThreadCrash.zip

@akien-mga
Copy link
Member

akien-mga commented Oct 30, 2023

I don't reproduce the crash on Linux with 4.2-beta3 or 4.x 5dc10b5. Might be Windows specific.

@Jordyfel
Copy link
Contributor

image

I can reproduce something going wrong, but VSCode is not giving me a stack trace. (Windows 11)

@akien-mga
Copy link
Member

@Chaosus Can you reproduce the issue in 4.1.x too, or is it a 4.2 regression?

@adamscott adamscott self-assigned this Oct 31, 2023
@Chaosus
Copy link
Member Author

Chaosus commented Oct 31, 2023

@akien-mga Nope, 4.1.2 is okay, I guess its 4.2 regression

@YuriSizov
Copy link
Contributor

Can confirm this happens on Windows 11.

godot.windows.editor.dev.x86_64.exe!mtx_do_lock(_Mtx_internal_imp_t * mtx, const xtime * target) Line 100 (d:\a\_work\1\s\src\vctools\crt\github\stl\src\mutex.cpp:100)
godot.windows.editor.dev.x86_64.exe!std::_Mutex_base::lock() Line 48 (c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\mutex:48)
godot.windows.editor.dev.x86_64.exe!std::unique_lock<std::recursive_mutex>::unique_lock<std::recursive_mutex>(std::recursive_mutex & _Mtx) Line 124 (c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\mutex:124)
godot.windows.editor.dev.x86_64.exe!MutexLock<MutexImpl<std::recursive_mutex>>::MutexLock<MutexImpl<std::recursive_mutex>>(const MutexImpl<std::recursive_mutex> & p_mutex) Line 122 (c:\Projects\godot-engine\master\core\os\mutex.h:122)
godot.windows.editor.dev.x86_64.exe!GDScript::clear(GDScript::ClearData * p_clear_data) Line 1440 (c:\Projects\godot-engine\master\modules\gdscript\gdscript.cpp:1440)
godot.windows.editor.dev.x86_64.exe!GDScript::~GDScript() Line 1518 (c:\Projects\godot-engine\master\modules\gdscript\gdscript.cpp:1518)
godot.windows.editor.dev.x86_64.exe!GDScript::`scalar deleting destructor'(unsigned int) (Unknown Source:0)
godot.windows.editor.dev.x86_64.exe!memdelete<GDScript>(GDScript * p_class) Line 112 (c:\Projects\godot-engine\master\core\os\memory.h:112)
godot.windows.editor.dev.x86_64.exe!Ref<GDScript>::unref() Line 212 (c:\Projects\godot-engine\master\core\object\ref_counted.h:212)
godot.windows.editor.dev.x86_64.exe!Ref<GDScript>::~Ref<GDScript>() Line 223 (c:\Projects\godot-engine\master\core\object\ref_counted.h:223)
godot.windows.editor.dev.x86_64.exe!KeyValue<String,Ref<GDScript>>::~KeyValue<String,Ref<GDScript>>() (Unknown Source:0)
godot.windows.editor.dev.x86_64.exe!HashMapElement<String,Ref<GDScript>>::~HashMapElement<String,Ref<GDScript>>() (Unknown Source:0)
godot.windows.editor.dev.x86_64.exe!HashMapElement<String,Ref<GDScript>>::`scalar deleting destructor'(unsigned int) (Unknown Source:0)
godot.windows.editor.dev.x86_64.exe!memdelete<HashMapElement<String,Ref<GDScript>>>(HashMapElement<String,Ref<GDScript>> * p_class) Line 112 (c:\Projects\godot-engine\master\core\os\memory.h:112)
godot.windows.editor.dev.x86_64.exe!DefaultTypedAllocator<HashMapElement<String,Ref<GDScript>>>::delete_allocation(HashMapElement<String,Ref<GDScript>> * p_allocation) Line 206 (c:\Projects\godot-engine\master\core\os\memory.h:206)
godot.windows.editor.dev.x86_64.exe!HashMap<String,Ref<GDScript>,HashMapHasherDefault,HashMapComparatorDefault<String>,DefaultTypedAllocator<HashMapElement<String,Ref<GDScript>>>>::clear() Line 266 (c:\Projects\godot-engine\master\core\templates\hash_map.h:266)
godot.windows.editor.dev.x86_64.exe!GDScriptCache::clear() Line 445 (c:\Projects\godot-engine\master\modules\gdscript\gdscript_cache.cpp:445)
godot.windows.editor.dev.x86_64.exe!GDScriptLanguage::finish() Line 2116 (c:\Projects\godot-engine\master\modules\gdscript\gdscript.cpp:2116)
godot.windows.editor.dev.x86_64.exe!ScriptServer::finish_languages() Line 230 (c:\Projects\godot-engine\master\core\object\script_language.cpp:230)
godot.windows.editor.dev.x86_64.exe!Main::cleanup(bool p_force) Line 3763 (c:\Projects\godot-engine\master\main\main.cpp:3763)

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