diff --git a/Windows/W32Util/DialogManager.cpp b/Windows/W32Util/DialogManager.cpp index e3ee7b773..b40563bc0 100644 --- a/Windows/W32Util/DialogManager.cpp +++ b/Windows/W32Util/DialogManager.cpp @@ -1,5 +1,6 @@ #include "Common/CommonWindows.h" #include +#include #include "Windows/W32Util/DialogManager.h" @@ -68,6 +69,11 @@ void DialogManager::AddDlg(Dialog *dialog) dialogs.push_back(dialog); } +void DialogManager::RemoveDlg(Dialog *dialog) +{ + dialogs.erase(std::remove(dialogs.begin(), dialogs.end(), dialog), dialogs.end()); +} + bool DialogManager::IsDialogMessage(LPMSG message) { diff --git a/Windows/W32Util/DialogManager.h b/Windows/W32Util/DialogManager.h index 15a657c4a..7203b0460 100644 --- a/Windows/W32Util/DialogManager.h +++ b/Windows/W32Util/DialogManager.h @@ -37,6 +37,7 @@ class DialogManager { public: static void AddDlg(Dialog *dialog); + static void RemoveDlg(Dialog *dialog); static bool IsDialogMessage(LPMSG message); static void EnableAll(BOOL enable); static void DestroyAll(); diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index fb5078cb2..a29393294 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -828,6 +828,23 @@ namespace MainWindow DialogManager::AddDlg(memoryWindow[0]); } + void DestroyDebugWindows() { + DialogManager::RemoveDlg(disasmWindow[0]); + if (disasmWindow[0]) + delete disasmWindow[0]; + disasmWindow[0] = 0; + + DialogManager::RemoveDlg(geDebuggerWindow); + if (geDebuggerWindow) + delete geDebuggerWindow; + geDebuggerWindow = 0; + + DialogManager::RemoveDlg(memoryWindow[0]); + if (memoryWindow[0]) + delete memoryWindow[0]; + memoryWindow[0] = 0; + } + void BrowseAndBoot(std::string defaultPath, bool browseDirectory) { static std::wstring filter = L"All supported file types (*.iso *.cso *.pbp *.elf *.prx *.zip)|*.pbp;*.elf;*.iso;*.cso;*.prx;*.zip|PSP ROMs (*.iso *.cso *.pbp *.elf *.prx)|*.pbp;*.elf;*.iso;*.cso;*.prx|Homebrew/Demos installers (*.zip)|*.zip|All files (*.*)|*.*||"; for (int i = 0; i < (int)filter.length(); i++) { @@ -1334,15 +1351,18 @@ namespace MainWindow break; case ID_DEBUG_DISASSEMBLY: - disasmWindow[0]->Show(true); + if (disasmWindow[0]) + disasmWindow[0]->Show(true); break; case ID_DEBUG_GEDEBUGGER: - geDebuggerWindow->Show(true); + if (geDebuggerWindow) + geDebuggerWindow->Show(true); break; case ID_DEBUG_MEMORYVIEW: - memoryWindow[0]->Show(true); + if (memoryWindow[0]) + memoryWindow[0]->Show(true); break; case ID_DEBUG_EXTRACTFILE: @@ -1549,10 +1569,13 @@ namespace MainWindow break; case WM_USER + 1: - disasmWindow[0]->NotifyMapLoaded(); - memoryWindow[0]->NotifyMapLoaded(); + if (disasmWindow[0]) + disasmWindow[0]->NotifyMapLoaded(); + if (memoryWindow[0]) + memoryWindow[0]->NotifyMapLoaded(); - disasmWindow[0]->UpdateDialog(); + if (disasmWindow[0]) + disasmWindow[0]->UpdateDialog(); SetForegroundWindow(hwndMain); break; diff --git a/Windows/WndMainWindow.h b/Windows/WndMainWindow.h index 71d91faff..9b4473a4b 100644 --- a/Windows/WndMainWindow.h +++ b/Windows/WndMainWindow.h @@ -51,6 +51,7 @@ namespace MainWindow void Init(HINSTANCE hInstance); BOOL Show(HINSTANCE hInstance, int nCmdShow); void CreateDebugWindows(); + void DestroyDebugWindows(); void Close(); void UpdateMenus(); void UpdateCommands(); diff --git a/Windows/main.cpp b/Windows/main.cpp index 57cb591fe..11a5250c2 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -343,7 +343,6 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin CtrlRegisterList::init(); CGEDebugger::Init(); - DialogManager::AddDlg(memoryWindow[0] = new CMemoryDlg(_hInstance, hwndMain, currentDebugMIPS)); DialogManager::AddDlg(vfpudlg = new CVFPUDlg(_hInstance, hwndMain, currentDebugMIPS)); host = new WindowsHost(hwndMain, hwndDisplay); @@ -380,7 +379,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin accel = hAccelTable; break; case WINDOW_CPUDEBUGGER: - wnd = disasmWindow[0]->GetDlgHandle(); + wnd = disasmWindow[0] ? disasmWindow[0]->GetDlgHandle() : 0; accel = hDebugAccelTable; break; case WINDOW_GEDEBUGGER: @@ -405,6 +404,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin EmuThread_Stop(); + MainWindow::DestroyDebugWindows(); DialogManager::DestroyAll(); timeEndPeriod(1); delete host;