From f056fedae2542290a62158af80c70897b4cb9207 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 19 Sep 2004 01:38:12 +0000 Subject: [PATCH] fix crashes when fullscreen d3d window loses focus --- stepmania/src/RageDisplay.h | 2 +- stepmania/src/RageDisplay_D3D.cpp | 13 ++++++++++--- stepmania/src/RageDisplay_D3D.h | 2 +- stepmania/src/RageDisplay_Null.h | 2 +- stepmania/src/RageDisplay_OGL.cpp | 7 ++++--- stepmania/src/RageDisplay_OGL.h | 2 +- stepmania/src/ScreenManager.cpp | 3 ++- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 9871e8c350..6caaf161b4 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -158,7 +158,7 @@ public: /* Call this when the resolution has been changed externally: */ virtual void ResolutionChanged() { } - virtual void BeginFrame() = 0; + virtual bool BeginFrame() = 0; virtual void EndFrame() = 0; virtual VideoModeParams GetVideoModeParams() const = 0; bool IsWindowed() const { return this->GetVideoModeParams().windowed; } diff --git a/stepmania/src/RageDisplay_D3D.cpp b/stepmania/src/RageDisplay_D3D.cpp index c9d0481d09..825308344c 100644 --- a/stepmania/src/RageDisplay_D3D.cpp +++ b/stepmania/src/RageDisplay_D3D.cpp @@ -620,16 +620,23 @@ int RageDisplay_D3D::GetMaxTextureSize() const return g_DeviceCaps.MaxTextureWidth; } -void RageDisplay_D3D::BeginFrame() +bool RageDisplay_D3D::BeginFrame() { -#ifndef _XBOX - if( g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET ) +#if !defined(XBOX) + switch( g_pd3dDevice->TestCooperativeLevel() ) + { + case D3DERR_DEVICELOST: + return false; + case D3DERR_DEVICENOTRESET: SetVideoMode( g_CurrentParams ); + break; + } #endif g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0x00000000 ); g_pd3dDevice->BeginScene(); + return true; } void RageDisplay_D3D::EndFrame() diff --git a/stepmania/src/RageDisplay_D3D.h b/stepmania/src/RageDisplay_D3D.h index 1c5ca6d7da..02d35d9b89 100644 --- a/stepmania/src/RageDisplay_D3D.h +++ b/stepmania/src/RageDisplay_D3D.h @@ -26,7 +26,7 @@ public: void ResolutionChanged(); const PixelFormatDesc *GetPixelFormatDesc(PixelFormat pf) const; - void BeginFrame(); + bool BeginFrame(); void EndFrame(); VideoModeParams GetVideoModeParams() const; void SetBlendMode( BlendMode mode ); diff --git a/stepmania/src/RageDisplay_Null.h b/stepmania/src/RageDisplay_Null.h index a5470c8d0c..4012190019 100644 --- a/stepmania/src/RageDisplay_Null.h +++ b/stepmania/src/RageDisplay_Null.h @@ -12,7 +12,7 @@ public: void ResolutionChanged() { } const PixelFormatDesc *GetPixelFormatDesc(PixelFormat pf) const; - void BeginFrame() { } + bool BeginFrame() { return true; } void EndFrame(); VideoModeParams GetVideoModeParams() const { return m_Params; } void SetBlendMode( BlendMode mode ) { } diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index 47fee74497..253e9caf4a 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -743,8 +743,8 @@ void RageDisplay_OGL::ResolutionChanged() SetViewport(0,0); /* Clear any junk that's in the framebuffer. */ - BeginFrame(); - EndFrame(); + if( BeginFrame() ) + EndFrame(); } // Return true if mode change was successful. @@ -803,11 +803,12 @@ int RageDisplay_OGL::GetMaxTextureSize() const return size; } -void RageDisplay_OGL::BeginFrame() +bool RageDisplay_OGL::BeginFrame() { glClearColor( 0,0,0,1 ); SetZWrite( true ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + return true; } void RageDisplay_OGL::EndFrame() diff --git a/stepmania/src/RageDisplay_OGL.h b/stepmania/src/RageDisplay_OGL.h index 8d0967e1f5..e8928f8bc8 100644 --- a/stepmania/src/RageDisplay_OGL.h +++ b/stepmania/src/RageDisplay_OGL.h @@ -14,7 +14,7 @@ public: void ResolutionChanged(); const PixelFormatDesc *GetPixelFormatDesc(PixelFormat pf) const; - void BeginFrame(); + bool BeginFrame(); void EndFrame(); VideoModeParams GetVideoModeParams() const; void SetBlendMode( BlendMode mode ); diff --git a/stepmania/src/ScreenManager.cpp b/stepmania/src/ScreenManager.cpp index 860359a3ba..aa01f1e124 100644 --- a/stepmania/src/ScreenManager.cpp +++ b/stepmania/src/ScreenManager.cpp @@ -469,7 +469,8 @@ void ScreenManager::Draw() if( m_ScreenStack.back()->IsFirstUpdate() ) return; - DISPLAY->BeginFrame(); + if( !DISPLAY->BeginFrame() ) + return; if( !m_ScreenStack.empty() && !m_ScreenStack.back()->IsTransparent() ) // top screen isn't transparent m_ScreenStack.back()->Draw();