fix realese crash on win32

This commit is contained in:
Eduardo Bart 2012-01-17 21:07:22 -02:00
parent a1cee1e855
commit dddfdbc0d5
2 changed files with 19 additions and 35 deletions

View File

@ -124,8 +124,7 @@ void PlatformWindow::fireKeysPress()
ticks_t firstKeyPress = m_firstKeysPress[keyCode]; ticks_t firstKeyPress = m_firstKeysPress[keyCode];
if(g_clock.ticksElapsed(lastPressTicks) >= KEY_PRESS_REPEAT_INTERVAL) { if(g_clock.ticksElapsed(lastPressTicks) >= KEY_PRESS_REPEAT_INTERVAL) {
if(m_onInputEvent) { if(m_onInputEvent) {
m_inputEvent.reset(); m_inputEvent.reset(Fw::KeyPressInputEvent);
m_inputEvent.type = Fw::KeyPressInputEvent;
m_inputEvent.keyCode = keyCode; m_inputEvent.keyCode = keyCode;
m_inputEvent.wouldFilter = g_clock.ticksElapsed(firstKeyPress) < KEY_PRESS_REPEAT_DELAY; m_inputEvent.wouldFilter = g_clock.ticksElapsed(firstKeyPress) < KEY_PRESS_REPEAT_DELAY;
m_onInputEvent(m_inputEvent); m_onInputEvent(m_inputEvent);

View File

@ -332,14 +332,15 @@ void WIN32Window::internalCreateGLContext()
bool WIN32Window::isExtensionSupported(const char *ext) bool WIN32Window::isExtensionSupported(const char *ext)
{ {
typedef const char* _wglGetExtensionsStringARB(HDC hdc); typedef const char* (__cdecl * wglGetExtensionsStringProc)(HDC hdc);
_wglGetExtensionsStringARB *wglGetExtensionsStringARB = (_wglGetExtensionsStringARB*)getExtensionProcAddress("wglGetExtensionsStringARB"); wglGetExtensionsStringProc wglGetExtensionsString = (wglGetExtensionsStringProc)getExtensionProcAddress("wglGetExtensionsStringEXT");
if(!wglGetExtensionsString)
return false;
if(wglGetExtensionsStringARB) { const char *exts = wglGetExtensionsString(m_deviceContext);
const char *exts = wglGetExtensionsStringARB(m_deviceContext); if(exts && strstr(exts, ext))
if(strstr(exts, ext))
return true; return true;
}
return false; return false;
} }
@ -399,16 +400,7 @@ void WIN32Window::poll()
LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
m_inputEvent.reset();
/*
m_inputEvent.keyboardModifiers = 0;
if(HIWORD(GetKeyState(VK_CONTROL)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardCtrlModifier;
if(HIWORD(GetKeyState(VK_MENU)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardAltModifier;
if(HIWORD(GetKeyState(VK_SHIFT)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardShiftModifier;
*/
switch(uMsg) switch(uMsg)
{ {
case WM_ACTIVATE: { case WM_ACTIVATE: {
@ -419,7 +411,6 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
if(wParam >= 32 && wParam <= 255) { if(wParam >= 32 && wParam <= 255) {
m_inputEvent.reset(Fw::KeyTextInputEvent); m_inputEvent.reset(Fw::KeyTextInputEvent);
m_inputEvent.keyText = wParam; m_inputEvent.keyText = wParam;
m_onInputEvent(m_inputEvent);
} }
break; break;
} }
@ -438,37 +429,31 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
case WM_LBUTTONDOWN: { case WM_LBUTTONDOWN: {
m_inputEvent.reset(Fw::MousePressInputEvent); m_inputEvent.reset(Fw::MousePressInputEvent);
m_inputEvent.mouseButton = Fw::MouseLeftButton; m_inputEvent.mouseButton = Fw::MouseLeftButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_LBUTTONUP: { case WM_LBUTTONUP: {
m_inputEvent.reset(Fw::MouseReleaseInputEvent); m_inputEvent.reset(Fw::MouseReleaseInputEvent);
m_inputEvent.mouseButton = Fw::MouseLeftButton; m_inputEvent.mouseButton = Fw::MouseLeftButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MBUTTONDOWN: { case WM_MBUTTONDOWN: {
m_inputEvent.reset(Fw::MousePressInputEvent); m_inputEvent.reset(Fw::MousePressInputEvent);
m_inputEvent.mouseButton = Fw::MouseMidButton; m_inputEvent.mouseButton = Fw::MouseMidButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MBUTTONUP: { case WM_MBUTTONUP: {
m_inputEvent.reset(Fw::MouseReleaseInputEvent); m_inputEvent.reset(Fw::MouseReleaseInputEvent);
m_inputEvent.mouseButton = Fw::MouseMidButton; m_inputEvent.mouseButton = Fw::MouseMidButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_RBUTTONDOWN: { case WM_RBUTTONDOWN: {
m_inputEvent.reset(Fw::MousePressInputEvent); m_inputEvent.reset(Fw::MousePressInputEvent);
m_inputEvent.mouseButton = Fw::MouseRightButton; m_inputEvent.mouseButton = Fw::MouseRightButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_RBUTTONUP: { case WM_RBUTTONUP: {
m_inputEvent.reset(Fw::MouseReleaseInputEvent); m_inputEvent.reset(Fw::MouseReleaseInputEvent);
m_inputEvent.mouseButton = Fw::MouseRightButton; m_inputEvent.mouseButton = Fw::MouseRightButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MOUSEMOVE: { case WM_MOUSEMOVE: {
@ -476,14 +461,11 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
Point newMousePos(LOWORD(lParam), HIWORD(lParam)); Point newMousePos(LOWORD(lParam), HIWORD(lParam));
m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos; m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos;
m_inputEvent.mousePos = newMousePos; m_inputEvent.mousePos = newMousePos;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MOUSEWHEEL: { case WM_MOUSEWHEEL: {
m_inputEvent.reset(Fw::MouseWheelInputEvent);
m_inputEvent.mouseButton = Fw::MouseMidButton; m_inputEvent.mouseButton = Fw::MouseMidButton;
m_inputEvent.wheelDirection = HIWORD(wParam) > 0 ? Fw::MouseWheelUp : Fw::MouseWheelDown; m_inputEvent.wheelDirection = HIWORD(wParam) > 0 ? Fw::MouseWheelUp : Fw::MouseWheelDown;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MOVE: { case WM_MOVE: {
@ -512,6 +494,8 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
return DefWindowProc(hWnd, uMsg, wParam, lParam); return DefWindowProc(hWnd, uMsg, wParam, lParam);
} }
if(m_onInputEvent && m_inputEvent.type != Fw::NoInputEvent)
m_onInputEvent(m_inputEvent);
return 0; return 0;
} }
@ -581,14 +565,15 @@ void WIN32Window::setFullscreen(bool fullscreen)
void WIN32Window::setVerticalSync(bool enable) void WIN32Window::setVerticalSync(bool enable)
{ {
typedef int (*glSwapIntervalProc)(int); if(!isExtensionSupported("WGL_EXT_swap_control"))
glSwapIntervalProc glSwapInterval = NULL; return;
if(isExtensionSupported("WGL_EXT_swap_control")) typedef BOOL (WINAPI * wglSwapIntervalProc)(int);
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("wglSwapIntervalEXT"); wglSwapIntervalProc wglSwapInterval = (wglSwapIntervalProc)getExtensionProcAddress("wglSwapIntervalEXT");
if(!wglSwapInterval)
return;
if(glSwapInterval) wglSwapInterval(enable ? 1 : 0);
glSwapInterval(enable ? 1 : 0);
} }
void WIN32Window::setIcon(const std::string& pngIcon) void WIN32Window::setIcon(const std::string& pngIcon)