From acac470f7bba2608ac3a18fdb89abe53f47d9b94 Mon Sep 17 00:00:00 2001 From: johnangel Date: Wed, 19 Sep 2012 19:36:09 +0200 Subject: [PATCH] Fixing GPF when old OpenGL version is detected --- cocos2dx/platform/CCEGLViewProtocol.cpp | 4 +++- cocos2dx/platform/CCEGLViewProtocol.h | 2 +- cocos2dx/platform/win32/CCEGLView.cpp | 30 ++++++++++++++++++------- cocos2dx/platform/win32/CCEGLView.h | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index cd6ea0fbe7..1ee477f4c5 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -112,9 +112,11 @@ const CCSize& CCEGLViewProtocol::getFrameSize() const return m_obScreenSize; } -void CCEGLViewProtocol::setFrameSize(float width, float height) +bool CCEGLViewProtocol::setFrameSize(float width, float height) { m_obDesignResolutionSize = m_obScreenSize = CCSizeMake(width, height); + + return true; } CCSize CCEGLViewProtocol::getVisibleSize() const diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index f0db5bf7f5..b2bf422326 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -64,7 +64,7 @@ public: /** * Set the frame size of EGL view. */ - virtual void setFrameSize(float width, float height); + virtual bool setFrameSize(float width, float height); /** * Get the visible area size of opengl viewport. diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index b21ae220d4..f3060ff091 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -65,7 +65,7 @@ static void SetupPixelFormat(HDC hDC) SetPixelFormat(hDC, pixelFormat, &pfd); } -void glew_dynamic_binding() +bool glew_dynamic_binding() { const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS); @@ -100,7 +100,7 @@ void glew_dynamic_binding() else if (strstr(gl_extensions, "EXT_framebuffer_object")) { - CCLog("GL: EXT_framebuffer_object is supported\n"); + CCLog("OpenGL: EXT_framebuffer_object is supported\n"); glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT"); glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT"); glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT"); @@ -123,8 +123,10 @@ void glew_dynamic_binding() { CCLog("OpenGL: No framebuffers extension is supported\n"); CCLog("OpenGL: Any call to Fbo will crash!\n"); + return false; } } + return true; } ////////////////////////////////////////////////////////////////////////// @@ -182,15 +184,16 @@ bool CCEGLView::initGL() { char strComplain[256] = {0}; sprintf(strComplain, - "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", + "OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.", glVersion); - CCMessageBox(strComplain, "OpenGL version tooooooooooold"); + CCMessageBox(strComplain, "OpenGL version too old"); + return false; } GLenum GlewInitResult = glewInit(); if (GLEW_OK != GlewInitResult) { - fprintf(stderr,"ERROR: %s\n",glewGetErrorString(GlewInitResult)); + CCMessageBox((char *)glewGetErrorString(GlewInitResult), "OpenGL error"); return false; } @@ -212,7 +215,11 @@ bool CCEGLView::initGL() CCLog("OpenGL 2.0 not supported"); } - glew_dynamic_binding(); + if(glew_dynamic_binding() == false) + { + CCMessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error"); + return false; + } return true; } @@ -277,6 +284,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) resize(w, h); bRet = initGL(); + if(!bRet) destroyGL(); CC_BREAK_IF(!bRet); s_pMainWindow = this; @@ -536,13 +544,19 @@ void CCEGLView::resize(int width, int height) SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); } -void CCEGLView::setFrameSize(float width, float height) +bool CCEGLView::setFrameSize(float width, float height) { - Create((LPCTSTR)m_szViewName, (int)width, (int)height); + if(!Create((LPCTSTR)m_szViewName, (int)width, (int)height)) + { + PostQuitMessage(-1); + return false; + } CCEGLViewProtocol::setFrameSize(width, height); resize(width, height); // adjust window size for menubar centerWindow(); + + return true; } void CCEGLView::centerWindow() diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 2f8877772a..147cc16379 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -47,7 +47,7 @@ public: virtual void end(); virtual void swapBuffers(); virtual bool setContentScaleFactor(float contentScaleFactor); - virtual void setFrameSize(float width, float height); + virtual bool setFrameSize(float width, float height); virtual void setIMEKeyboardState(bool bOpen); virtual bool enableRetina();