From 3e773f093df179370faff6021a5c9a85af6181f7 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Mon, 19 Dec 2011 15:13:26 -0800 Subject: [PATCH] fixed a freeze on emu shutdown in windows build --- Source/Core/VideoCommon/Src/EmuWindow.cpp | 30 +++++++++++++++++++ Source/Core/VideoCommon/Src/EmuWindow.h | 1 + Source/Plugins/Plugin_VideoDX11/Src/main.cpp | 6 ++-- Source/Plugins/Plugin_VideoDX9/Src/main.cpp | 2 +- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 5 ++-- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/Src/EmuWindow.cpp b/Source/Core/VideoCommon/Src/EmuWindow.cpp index ff96887a32..30dca24cb1 100644 --- a/Source/Core/VideoCommon/Src/EmuWindow.cpp +++ b/Source/Core/VideoCommon/Src/EmuWindow.cpp @@ -36,6 +36,9 @@ WNDCLASSEX wndClass; const TCHAR m_szClassName[] = _T("DolphinEmuWnd"); int g_winstyle; static volatile bool s_sizing; +static const int TITLE_TEXT_BUF_SIZE = 1024; +TCHAR m_titleTextBuffer[TITLE_TEXT_BUF_SIZE]; +static const int WM_SETTEXT_CUSTOM = WM_USER + WM_SETTEXT; bool IsSizing() { @@ -225,6 +228,10 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam ) PostMessage(m_hParent, WM_USER, WM_USER_SETCURSOR, 0); return true; + case WM_SETTEXT_CUSTOM: + SendMessage(hWnd, WM_SETTEXT, wParam, lParam); + break; + default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } @@ -357,4 +364,27 @@ void SetSize(int width, int height) MoveWindow(m_hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE); } +void SetWindowText(const TCHAR* text) +{ + // the simple way. + // we don't do this because it's a blocking call and the GUI thread might be waiting for us. + //::SetWindowText(m_hWnd, text); + + // copy to m_titleTextBuffer in such a way that + // it remains null-terminated and without garbage data at every point in time, + // in case another thread reads it while we're doing this. + for (int i = 0; i < TITLE_TEXT_BUF_SIZE-1; ++i) + { + m_titleTextBuffer[i+1] = 0; + TCHAR c = text[i]; + m_titleTextBuffer[i] = c; + if (!c) + break; + } + + // the OS doesn't allow posting WM_SETTEXT, + // so we post our own message and convert it to that in WndProc + PostMessage(m_hWnd, WM_SETTEXT_CUSTOM, 0, (LPARAM)m_titleTextBuffer); +} + } diff --git a/Source/Core/VideoCommon/Src/EmuWindow.h b/Source/Core/VideoCommon/Src/EmuWindow.h index 1403ffcf57..bf5aa73cdf 100644 --- a/Source/Core/VideoCommon/Src/EmuWindow.h +++ b/Source/Core/VideoCommon/Src/EmuWindow.h @@ -14,6 +14,7 @@ void Close(); void SetSize(int displayWidth, int displayHeight); bool IsSizing(); void OSDMenu(WPARAM wParam); +void SetWindowText(const TCHAR* text); } diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp index ba93890e2b..f6fe1127a3 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp @@ -68,9 +68,9 @@ unsigned int VideoBackend::PeekMessages() void VideoBackend::UpdateFPSDisplay(const char *text) { - char temp[512]; - sprintf_s(temp, sizeof temp, "%s | DX11 | %s", scm_rev_str, text); - SetWindowTextA(EmuWindow::GetWnd(), temp); + TCHAR temp[512]; + swprintf_s(temp, sizeof(temp)/sizeof(TCHAR), _T("%hs | DX11 | %hs"), scm_rev_str, text); + EmuWindow::SetWindowText(temp); } std::string VideoBackend::GetName() diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index 1d733f7dc3..727fa73a00 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -78,7 +78,7 @@ void VideoBackend::UpdateFPSDisplay(const char *text) { TCHAR temp[512]; swprintf_s(temp, sizeof(temp)/sizeof(TCHAR), _T("%hs | DX9 | %hs"), scm_rev_str, text); - SetWindowText(EmuWindow::GetWnd(), temp); + EmuWindow::SetWindowText(temp); } std::string VideoBackend::GetName() diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index bedcaa6245..cbdb702885 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -73,8 +73,9 @@ void OpenGL_SetWindowText(const char *text) #elif defined(__APPLE__) [GLWin.cocoaWin setTitle: [NSString stringWithUTF8String: text]]; #elif defined(_WIN32) - // TODO convert text to unicode and change SetWindowTextA to SetWindowText - SetWindowTextA(EmuWindow::GetWnd(), text); + TCHAR temp[512]; + swprintf_s(temp, sizeof(temp)/sizeof(TCHAR), _T("%hs"), text); + EmuWindow::SetWindowText(temp); #elif defined(HAVE_X11) && HAVE_X11 // Tell X to ask the window manager to set the window title. // (X itself doesn't provide window title functionality.)