From 34fec9cb85f6e22773aba9ee7c9ee34bc8752868 Mon Sep 17 00:00:00 2001 From: janwas Date: Sun, 1 Jun 2008 10:19:17 +0000 Subject: [PATCH] preemptive fix: prevent CRT error messages generated after PostQuitMessage from vanishing This was SVN commit r6005. --- source/lib/sysdep/win/wsdl.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/source/lib/sysdep/win/wsdl.cpp b/source/lib/sysdep/win/wsdl.cpp index 7a0fff7b7b..6aed6fbb11 100644 --- a/source/lib/sysdep/win/wsdl.cpp +++ b/source/lib/sysdep/win/wsdl.cpp @@ -911,6 +911,25 @@ int SDL_ShowCursor(int toggle) //---------------------------------------------------------------------------- +static LRESULT OnDestroy(HWND hWnd) +{ + debug_assert(hWnd == g_hWnd); + WARN_IF_FALSE(ReleaseDC(g_hWnd, g_hDC)); + g_hDC = (HDC)INVALID_HANDLE_VALUE; + g_hWnd = (HWND)INVALID_HANDLE_VALUE; + queue_quit_event(); + PostQuitMessage(0); + + // see http://www.adrianmccarthy.com/blog/?p=51 + // with WM_QUIT in the message queue, MessageBox will immediately + // return IDABORT. to ensure any subsequent CRT error reports are + // at least somewhat visible, we redirect them to debug output. + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); + + return 0; +} + + static LRESULT CALLBACK wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if(is_quitting) @@ -936,14 +955,7 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar break; HANDLE_MSG(hWnd, WM_ACTIVATE, OnActivate); - - case WM_DESTROY: - WARN_IF_FALSE(ReleaseDC(g_hWnd, g_hDC)); - g_hDC = (HDC)INVALID_HANDLE_VALUE; - g_hWnd = (HWND)INVALID_HANDLE_VALUE; - queue_quit_event(); - PostQuitMessage(0); - break; + HANDLE_MSG(hWnd, WM_DESTROY, OnDestroy); case WM_SYSCOMMAND: switch(wParam)