- changed the place where the CheckRequireMouse event gets called.

The original place in I_CheckNativeMouse is unsafe because that function can get called from the system message queue which can result in a bad global state of the VM for such a call because it can be recursively invoked from code that may temporarily alter some settings.
This commit is contained in:
Christoph Oelckers 2019-02-02 11:00:26 +01:00
parent 484485f3cf
commit d005e0b483
3 changed files with 10 additions and 6 deletions

View file

@ -150,6 +150,9 @@ extern bool AppActive;
int SessionState = 0; int SessionState = 0;
int BlockMouseMove; int BlockMouseMove;
static bool EventHandlerResultForNativeMouse;
CVAR (Bool, i_soundinbackground, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, i_soundinbackground, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
@ -457,11 +460,11 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0; return 0;
case WM_KILLFOCUS: case WM_KILLFOCUS:
I_CheckNativeMouse (true); // Make sure mouse gets released right away I_CheckNativeMouse (true, false); // Make sure mouse gets released right away
break; break;
case WM_SETFOCUS: case WM_SETFOCUS:
I_CheckNativeMouse (false); I_CheckNativeMouse (false, EventHandlerResultForNativeMouse); // This cannot call the event handler. Doing it from here is unsafe.
break; break;
case WM_SETCURSOR: case WM_SETCURSOR:
@ -778,7 +781,8 @@ void I_StartTic ()
BlockMouseMove--; BlockMouseMove--;
ResetButtonTriggers (); ResetButtonTriggers ();
I_CheckGUICapture (); I_CheckGUICapture ();
I_CheckNativeMouse (false); EventHandlerResultForNativeMouse = eventManager.CheckRequireMouse();
I_CheckNativeMouse (false, EventHandlerResultForNativeMouse);
I_GetEvent (); I_GetEvent ();
} }

View file

@ -129,7 +129,7 @@ public:
extern FJoystickCollection *JoyDevices[NUM_JOYDEVICES]; extern FJoystickCollection *JoyDevices[NUM_JOYDEVICES];
void I_StartupMouse(); void I_StartupMouse();
void I_CheckNativeMouse(bool prefer_native); void I_CheckNativeMouse(bool prefer_native, bool eh);
void I_StartupKeyboard(); void I_StartupKeyboard();
void I_StartupXInput(); void I_StartupXInput();
void I_StartupDirectInputJoystick(); void I_StartupDirectInputJoystick();

View file

@ -284,7 +284,7 @@ static bool CaptureMode_InGame()
// //
//========================================================================== //==========================================================================
void I_CheckNativeMouse(bool preferNative) void I_CheckNativeMouse(bool preferNative, bool eventhandlerresult)
{ {
bool windowed = (screen == NULL) || !screen->IsFullscreen(); bool windowed = (screen == NULL) || !screen->IsFullscreen();
bool want_native; bool want_native;
@ -311,7 +311,7 @@ void I_CheckNativeMouse(bool preferNative)
} }
} }
if (!want_native && eventManager.CheckRequireMouse()) if (!want_native && eventhandlerresult)
want_native = true; want_native = true;
//Printf ("%d %d %d\n", wantNative, preferNative, NativeMouse); //Printf ("%d %d %d\n", wantNative, preferNative, NativeMouse);