From 2a85a2b9df24140a1348966edbb29567cee21aa8 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 30 May 2003 00:30:40 +0000 Subject: [PATCH] Fix crash alt+tabbing in and out of fullscreen on Voodoo3+D3D+WinXP. --- stepmania/src/NoteData.cpp | 2 +- stepmania/src/RageDisplay_D3D.cpp | 35 +++++++++++++++++++++++++++++-- stepmania/src/SDL_utils.cpp | 6 ++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/stepmania/src/NoteData.cpp b/stepmania/src/NoteData.cpp index ff3be7b197..ac9f9217f5 100644 --- a/stepmania/src/NoteData.cpp +++ b/stepmania/src/NoteData.cpp @@ -1007,7 +1007,7 @@ void NoteDataUtil::Wide( NoteData &in ) // make all all quarter notes jumps int max_row = in.GetLastRow(); - for( int i=0; i<=max_row; i+=ROWS_PER_BEAT ) + for( int i=0; i<=max_row; i+=ROWS_PER_BEAT*2 ) // every even beat { if( in.GetNumTapNonEmptyTracks(i) != 1 ) continue; // skip. Don't place during holds diff --git a/stepmania/src/RageDisplay_D3D.cpp b/stepmania/src/RageDisplay_D3D.cpp index 5900e0d640..76c4e0ff52 100644 --- a/stepmania/src/RageDisplay_D3D.cpp +++ b/stepmania/src/RageDisplay_D3D.cpp @@ -384,6 +384,8 @@ HWND GetHwnd() /* Set the video mode. */ bool RageDisplay_D3D::SetVideoMode( bool windowed, int width, int height, int bpp, int rate, bool vsync, CString sWindowTitle, CString sIconFile ) { + HRESULT hr; + if( FindBackBufferType( windowed, bpp ) == -1 ) // no possible back buffer formats return false; @@ -391,6 +393,31 @@ bool RageDisplay_D3D::SetVideoMode( bool windowed, int width, int height, int bp SDL_WM_SetCaption(sWindowTitle, ""); mySDL_WM_SetIcon( sIconFile ); + + /* Round to the nearest valid fullscreen resolution */ + if( !windowed ) + { + if( width <= 320 ) width = 320; + else if( width <= 400 ) width = 400; + else if( width <= 512 ) width = 512; + else if( width <= 640 ) width = 640; + else if( width <= 800 ) width = 800; + else if( width <= 1024 ) width = 1024; + else if( width <= 1280 ) width = 1280; + + switch( width ) + { + case 320: height = 240; break; + case 400: height = 300; break; + case 512: height = 384; break; + case 640: height = 480; break; + case 800: height = 600; break; + case 1024: height = 768; break; + case 1280: height = 1024; break; + default: ASSERT(0); + } + } + // HACK: On Windows 98, we can't call SDL_SetVideoMode while D3D is full screen. // It will result in "SDL_SetVideoMode failed: DirectDraw2::CreateSurface(PRIMARY): @@ -435,7 +462,6 @@ bool RageDisplay_D3D::SetVideoMode( bool windowed, int width, int height, int bp if( bCreateNewDevice ) // device is not yet created. We need to create it { - HRESULT hr; hr = g_pd3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, @@ -456,7 +482,12 @@ bool RageDisplay_D3D::SetVideoMode( bool windowed, int width, int height, int bp } else { - g_pd3dDevice->Reset( &g_d3dpp ); + hr = g_pd3dDevice->Reset( &g_d3dpp ); + if( FAILED(hr) ) + { + SDL_QuitSubSystem(SDL_INIT_VIDEO); // exit out of full screen. The ~RageDisplay will not be called! + RageException::Throw( "g_pd3dDevice->Reset failed: '%s'", DXGetErrorString8(hr) ); + } } if( this->IsWindowed() ) diff --git a/stepmania/src/SDL_utils.cpp b/stepmania/src/SDL_utils.cpp index 7ec5366bb5..25297789ba 100644 --- a/stepmania/src/SDL_utils.cpp +++ b/stepmania/src/SDL_utils.cpp @@ -563,6 +563,12 @@ Uint8 mySDL_EventState(Uint8 type, int state) void mySDL_WM_SetIcon( CString sIconFile ) { + if( sIconFile.empty() ) + { + SDL_WM_SetIcon(NULL, NULL); + return; + } + SDL_Surface *srf = IMG_Load(sIconFile); SDL_SetColorKey( srf, SDL_SRCCOLORKEY, SDL_MapRGB(srf->format, 0xFF, 0, 0xFF));