From 2206e32cef6c654ce40de28e7c5f191d42bf798f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 25 Jun 2003 20:44:49 +0000 Subject: [PATCH] Simplify exception handling. Improve fallback if we can't set up an OpenGL window. --- stepmania/src/RageDisplay.cpp | 2 +- stepmania/src/RageDisplay_OGL.cpp | 20 ++++++++++++++++++-- stepmania/src/RageDisplay_OGL.h | 2 +- stepmania/src/StepMania.cpp | 19 ++++++++----------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index c09a5a3f4b..a7f3caedfa 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -92,7 +92,7 @@ bool RageDisplay::SetVideoMode( VideoModeParams p ) if( this->TryVideoMode(p,bNeedReloadTextures) ) return bNeedReloadTextures; - RageException::Throw( "SetVideoMode failed. Tried to fall back to other modes, but nothing worked." ); + RageException::ThrowNonfatal( "SetVideoMode failed. Tried to fall back to other modes, but nothing worked." ); } void RageDisplay::ProcessStatsOnFlip() diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index b58e3d13f0..976c6601ab 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -232,7 +232,7 @@ static void FlushGLErrors() ; } -RageDisplay_OGL::RageDisplay_OGL( VideoModeParams p ) +RageDisplay_OGL::RageDisplay_OGL( VideoModeParams p, bool bAllowUnacceleratedRenderer ) { LOG->Trace( "RageDisplay_OGL::RageDisplay_OGL()" ); LOG->MapLog("renderer", "Current renderer: OpenGL"); @@ -241,15 +241,31 @@ RageDisplay_OGL::RageDisplay_OGL( VideoModeParams p ) wind = MakeLowLevelWindow(); - SetVideoMode( p ); + try { + SetVideoMode( p ); + } catch(...) { + /* SetVideoMode can throw. */ + delete wind; + throw; + } // Log driver details LOG->Info("OGL Vendor: %s", glGetString(GL_VENDOR)); LOG->Info("OGL Renderer: %s", glGetString(GL_RENDERER)); LOG->Info("OGL Version: %s", glGetString(GL_VERSION)); LOG->Info("OGL Extensions: %s", glGetString(GL_EXTENSIONS)); + if( IsSoftwareRenderer() ) + { + if( !bAllowUnacceleratedRenderer ) + { + delete wind; + RageException::ThrowNonfatal( + "Your system is reporting that OpenGL hardware acceleration is not available. " + "Please obtain an updated driver from your video card manufacturer.\n\n" ); + } LOG->Warn("This is a software renderer!"); + } /* Log this, so if people complain that the radar looks bad on their diff --git a/stepmania/src/RageDisplay_OGL.h b/stepmania/src/RageDisplay_OGL.h index 82c3a13e4a..4811643aec 100644 --- a/stepmania/src/RageDisplay_OGL.h +++ b/stepmania/src/RageDisplay_OGL.h @@ -4,7 +4,7 @@ class RageDisplay_OGL: public RageDisplay { public: - RageDisplay_OGL( VideoModeParams params ); + RageDisplay_OGL( VideoModeParams params, bool bAllowUnacceleratedRenderer ); virtual ~RageDisplay_OGL(); void Update(float fDeltaTime); diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index addf28ac5b..09748dfae8 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -378,17 +378,12 @@ RageDisplay *CreateDisplay() * SDL may throw, but that only happens with broken driver installations, and * we probably don't want to fall back on D3D in that case anyway.) */ error += "Initializing OpenGL...\n"; - - RageDisplay *ret = new RageDisplay_OGL( params ); - - if( PREFSMAN->m_bAllowUnacceleratedRenderer || !ret->IsSoftwareRenderer() ) - return ret; - else - { - error += "Your system is reporting that OpenGL hardware acceleration is not available. " - "Please obtain an updated driver from your video card manufacturer.\n\n"; - delete ret; - } + try { + return new RageDisplay_OGL( params, PREFSMAN->m_bAllowUnacceleratedRenderer ); + } catch(RageException e) { + error += CString(e.what()) + "\n"; + continue; + }; #endif } else if( sRenderer.CompareNoCase("d3d")==0 ) @@ -402,6 +397,8 @@ RageDisplay *CreateDisplay() } catch(RageException_D3DNoAcceleration e) { error += "Your system is reporting that Direct3D hardware acceleration is not available. " "Please obtain an updated driver from your video card manufacturer.\n\n"; + } catch(RageException e) { + error += CString(e.what()) + "\n"; }; #endif }