fixed a freeze on emu shutdown in windows build

This commit is contained in:
nitsuja 2011-12-19 15:13:26 -08:00
parent 567e90bbd5
commit 3e773f093d
5 changed files with 38 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -14,6 +14,7 @@ void Close();
void SetSize(int displayWidth, int displayHeight);
bool IsSizing();
void OSDMenu(WPARAM wParam);
void SetWindowText(const TCHAR* text);
}

View File

@ -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()

View File

@ -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()

View File

@ -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.)