From b15d2c56f05001bff0f7d3b9456dcf8053f73759 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 28 Sep 2024 21:48:58 +0100 Subject: Fix crash on exit when our raw input is used Turns out window messages still get generated after the plugin is unloaded, causing now-unloaded SST code to get called. In some edge cases some Windows appCompat logic will also then start suppressing FreeLibrary calls for that game, which breaks plugin hot reloading. Very dumb and very confusing. I didn't notice the crashing before due to lack of minidumps from the relevant games, so thanks aciidz for pointing this issue out. --- src/rinput.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/rinput.c') diff --git a/src/rinput.c b/src/rinput.c index 3baa67c..1187e15 100644 --- a/src/rinput.c +++ b/src/rinput.c @@ -219,7 +219,6 @@ e0: UnregisterClassW(L"RInput", 0); } END { - if_hot (!sst_userunloaded) return; if_hot (orig_SetCursorPos) { // we inited our own implementation RAWINPUTDEVICE rd = { .dwFlags = RIDEV_REMOVE, @@ -229,11 +228,13 @@ END { }; RegisterRawInputDevices(&rd, 1, sizeof(rd)); DestroyWindow(inwin); + if_hot (!sst_userunloaded) return; UnregisterClassW(L"RInput", 0); unhook_inline((void *)orig_GetCursorPos); unhook_inline((void *)orig_SetCursorPos); } - else { // we must have hooked the *existing* implementation + else if_cold (sst_userunloaded) { + // we must have hooked the *existing* implementation unhook_vtable(vtable_insys, vtidx_GetRawMouseAccumulators, (void *)orig_GetRawMouseAccumulators); } -- cgit v1.2.3-54-g00ecf