From a8e73bc3d78e17df2616144e2871f5033e1ddfa0 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 17 Jan 2004 00:34:34 +0000 Subject: [PATCH] trying to fix crash handler hangs when subthreads crash while the main thread is holding a mutex --- stepmania/src/archutils/Win32/Crash.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/stepmania/src/archutils/Win32/Crash.cpp b/stepmania/src/archutils/Win32/Crash.cpp index e84a233b61..a1de4cd937 100644 --- a/stepmania/src/archutils/Win32/Crash.cpp +++ b/stepmania/src/archutils/Win32/Crash.cpp @@ -208,12 +208,19 @@ long __stdcall CrashHandler(EXCEPTION_POINTERS *pExc) ++InHere; /* Now things get more risky. If we're fullscreen, the window will obscure the - * crash dialog. Try to hide the window. We stopped threads above; we need to - * resume them now, or ShowWindow will deadlock. Things might blow up here; - * do this after DoSave, so we always write a crash dump. */ - RageThread::ResumeAllThreads(); - ShowWindow( g_hWndMain, SW_HIDE ); - RageThread::HaltAllThreads( false ); + * crash dialog. Try to hide the window. Things might blow up here; do this + * after DoSave, so we always write a crash dump. */ + if( GetWindowThreadProcessId( g_hWndMain, NULL ) == GetCurrentThreadId() ) + { + /* The thread that crashed was the thread that created the main window. Hide + * the window. This will also restore the video mode, if necessary. */ + ShowWindow( g_hWndMain, SW_HIDE ); + } else { + /* A different thread crashed. Simply kill all other windows. We can't safely + * call ShowWindow; the main thread might be deadlocked. */ + RageThread::HaltAllThreads( true ); + ChangeDisplaySettings(NULL, 0); + } if( g_bAutoRestart ) Win32RestartProgram();