Skip to content

Commit

Permalink
Win32Window: Ignore bad window size changes
Browse files Browse the repository at this point in the history
See: crash report #444
Hopefully this fixes it.
  • Loading branch information
dscharrer committed Jan 26, 2013
1 parent 04619c6 commit f62c1b1
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/window/Win32Window.cpp
Expand Up @@ -296,54 +296,61 @@ void* Win32Window::GetHandle() {
void Win32Window::updateSize() {

RECT rcClient;
GetClientRect(m_hWnd, &rcClient);
BOOL ret = GetClientRect(m_hWnd, &rcClient);

if(!ret || rcClient.right == rcClient.left || rcClient.bottom == rcClient.top) {
LogWarning << "Ignoring bad window size: (" << rcClient.left << ", " << rcClient.top
<< ") -- (" << rcClient.right << ", " << rcClient.bottom << ")";
}

Vec2i newSize = Vec2i(rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);

if(newSize != m_Size) {
OnResize(newSize.x, newSize.y);
OnResize(newSize.x, newSize.y);
changeDisplay(newSize, 0);
}
}

void Win32Window::setFullscreenMode(Vec2i resolution, unsigned _depth) {

SetWindowLong(m_hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);

depth = _depth;

SetWindowPos(m_hWnd, HWND_TOP, 0, 0, resolution.x, resolution.y, SWP_SHOWWINDOW);

if(!m_IsFullscreen) {
m_IsFullscreen = true;
OnToggleFullscreen();
}

OnResize(resolution.x, resolution.y);
}

void Win32Window::setWindowSize(Vec2i size) {

SetWindowLong(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);

depth = 0;

DWORD windowStyle = WS_OVERLAPPEDWINDOW;
DWORD windowExtendedStyle = WS_EX_APPWINDOW;

RECT rcWnd;

SetRect(&rcWnd, 0, 0, size.x, size.y);
AdjustWindowRectEx(&rcWnd, windowStyle, GetMenu(m_hWnd) != NULL, windowExtendedStyle);

int dx = rcWnd.right - rcWnd.left - size.x;
int dy = rcWnd.bottom - rcWnd.top - size.y;

SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, size.x + dx, size.y + dy, SWP_SHOWWINDOW);

if(m_IsFullscreen) {
m_IsFullscreen = false;
OnToggleFullscreen();
}

OnResize(size.x, size.y);
}

Expand Down

0 comments on commit f62c1b1

Please sign in to comment.