File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,3 +60,27 @@ struct GameExitHook : Modify<GameExitHook, CCDirector> {
6060#endif
6161
6262}
63+
64+ #ifdef GEODE_IS_WINDOWS
65+ $on_game(Exiting) {
66+ // On Windows, the game creates an std::thread in CCEGLView::setupWindow and stores it in a static variable,
67+ // but never joins it or calls detach on it. This leads to a call to std::terminate during static destruction,
68+ // and that may have unexpected consequences, such as stalling the game on restart and making it terminate abnormally.
69+ //
70+ // This fix simply detaches the thread before the game has a chance to do things improperly.
71+ // For people updating this to a newer GD version: look near the end of setupWindow:
72+ //
73+ // uVar4 = _beginthreadex(...);
74+ // ...
75+ // _DAT_1801a8530 = uVar4; <-- this is the address we want!
76+
77+ #if GEODE_COMP_GD_VERSION != 22081
78+ #pragma message("Unsupported GD version!")
79+ return ;
80+ #endif
81+
82+ auto addr = reinterpret_cast <void *>(geode::base::getCocos () + 0x1a8530 );
83+ auto thread = reinterpret_cast <std::thread*>(addr);
84+ if (thread->joinable ()) thread->detach ();
85+ }
86+ #endif
You can’t perform that action at this time.
0 commit comments