From 73812bdb01f74c84c909ef0af882ae3385768aba Mon Sep 17 00:00:00 2001 From: Maximilian Wittfeld Date: Thu, 21 Nov 2024 00:14:11 +0100 Subject: [PATCH] fix(game/five): updateBusySpinner thread constraint check This should work as a temporary fix to prevent crashes when for unknown reasons 'updateBusySpinner' gets called from the Render thread instead of the Main thread, which causes an inner function call to return a nullptr. due to failing thread constraint checks. --- .../loading-screens-five/src/HookLoadingScreens.cpp | 6 ++++++ code/components/rage-input-five/src/InputHook.cpp | 2 -- code/components/rage-nutsnbolts-five/include/nutsnbolts.h | 2 ++ code/components/rage-nutsnbolts-five/src/FrameHook.cpp | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/code/components/loading-screens-five/src/HookLoadingScreens.cpp b/code/components/loading-screens-five/src/HookLoadingScreens.cpp index 766e186858..63e59a9a87 100644 --- a/code/components/loading-screens-five/src/HookLoadingScreens.cpp +++ b/code/components/loading-screens-five/src/HookLoadingScreens.cpp @@ -483,6 +483,12 @@ static InitFunction initFunction([] () { if (*g_scaleformMgr) { + if (GetCurrentThreadId() != g_mainThreadId) + { + trace("Error: BusySpinner update called from non-main thread!\n"); + return; + } + setupBusySpinner(1); *spinnerDep = true; updateBusySpinner(); diff --git a/code/components/rage-input-five/src/InputHook.cpp b/code/components/rage-input-five/src/InputHook.cpp index a52751081a..96aba750c6 100644 --- a/code/components/rage-input-five/src/InputHook.cpp +++ b/code/components/rage-input-five/src/InputHook.cpp @@ -411,8 +411,6 @@ static hook::cdecl_stub ProcessWMChar([]() static ReverseGameInputState lastInput; static ReverseGameInputState curInput; -static bool g_mainThreadId; - #include extern void DoPatchMouseScrollDelta(); diff --git a/code/components/rage-nutsnbolts-five/include/nutsnbolts.h b/code/components/rage-nutsnbolts-five/include/nutsnbolts.h index 83a5480b2b..d366497fba 100644 --- a/code/components/rage-nutsnbolts-five/include/nutsnbolts.h +++ b/code/components/rage-nutsnbolts-five/include/nutsnbolts.h @@ -15,6 +15,8 @@ #define HAS_EARLY_GAME_FRAME +extern NUTSNBOLTS_EXPORT DWORD g_mainThreadId; + extern NUTSNBOLTS_EXPORT fwEvent<> OnLookAliveFrame; extern NUTSNBOLTS_EXPORT fwEvent<> OnGameFrame; extern NUTSNBOLTS_EXPORT fwEvent<> OnEarlyGameFrame; diff --git a/code/components/rage-nutsnbolts-five/src/FrameHook.cpp b/code/components/rage-nutsnbolts-five/src/FrameHook.cpp index 31c1275ddb..d35b6fe82d 100644 --- a/code/components/rage-nutsnbolts-five/src/FrameHook.cpp +++ b/code/components/rage-nutsnbolts-five/src/FrameHook.cpp @@ -13,6 +13,8 @@ #include #include +DWORD g_mainThreadId; + fwEvent<> OnLookAliveFrame; fwEvent<> OnEarlyGameFrame; fwEvent<> OnGameFrame; @@ -64,7 +66,6 @@ static uint32_t g_lastCriticalFrame; static std::mutex g_gameFrameMutex; static std::mutex g_earlyGameFrameMutex; static std::mutex g_criticalFrameMutex; -static DWORD g_mainThreadId; static bool g_executedOnMainThread; // NOTE: depends indirectly on GameProfiling.cpp in gta:core!