From 0ddb1917aa41a70f5770e50d3dbc333c0dafe23c Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 12 Dec 2020 17:46:36 +0000 Subject: [PATCH] SyncEvents: ensure MB & Mouse have removed their events for a restart --- source/Mockingboard.cpp | 3 +++ source/MouseInterface.h | 1 + source/Windows/AppleWin.cpp | 18 +++++++++++------- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/source/Mockingboard.cpp b/source/Mockingboard.cpp index 0f6daa0a..5c3dd19d 100644 --- a/source/Mockingboard.cpp +++ b/source/Mockingboard.cpp @@ -1649,6 +1649,9 @@ void MB_Destroy() for (int id=0; idm_active) + g_SynchronousEventMgr.Remove(id); + delete g_syncEvent[id]; g_syncEvent[id] = NULL; } diff --git a/source/MouseInterface.h b/source/MouseInterface.h index 6b142d1a..38168d0c 100644 --- a/source/MouseInterface.h +++ b/source/MouseInterface.h @@ -17,6 +17,7 @@ public: void Initialize(LPBYTE pCxRomPeripheral, UINT uSlot); // void Uninitialize(); void Reset(); + UINT GetSlot(void) { return m_uSlot; } static BYTE __stdcall IORead(WORD PC, WORD uAddr, BYTE bWrite, BYTE uValue, ULONG nExecutedCycles); static BYTE __stdcall IOWrite(WORD PC, WORD uAddr, BYTE bWrite, BYTE uValue, ULONG nExecutedCycles); diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index a8c52ebe..dd35cca7 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -653,19 +653,23 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) MB_Reset(); LogFileOutput("Main: MB_Reset()\n"); - CMouseInterface* pMouseCard = GetCardMgr().GetMouseCard(); - if (pMouseCard) + if (g_bRestart) { - pMouseCard->Reset(); // Deassert any pending IRQs - GH#514 - LogFileOutput("Main: CMouseInterface::Uninitialize()\n"); + CMouseInterface* pMouseCard = GetCardMgr().GetMouseCard(); + if (pMouseCard) + { + // dtor removes event from g_SynchronousEventMgr - do before g_SynchronousEventMgr.Reset() + GetCardMgr().Remove( pMouseCard->GetSlot() ); + LogFileOutput("Main: CMouseInterface::dtor\n"); + } + + _ASSERT(g_SynchronousEventMgr.GetHead() == NULL); + g_SynchronousEventMgr.Reset(); } DSUninit(); LogFileOutput("Main: DSUninit()\n"); - if (g_bRestart) - g_SynchronousEventMgr.Reset(); - if (g_bHookSystemKey) { UninitHookThread();