Skip to content

Commit e6298c2

Browse files
committed
Replicate in GeneralsMD
1 parent 730f83e commit e6298c2

File tree

1 file changed

+48
-29
lines changed
  • GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient

1 file changed

+48
-29
lines changed

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ static void drawFramerateBar(void);
116116
#endif
117117

118118
// DEFINE AND ENUMS ///////////////////////////////////////////////////////////
119-
#define W3D_DISPLAY_DEFAULT_BIT_DEPTH 32
120119

121120
#define no_SAMPLE_DYNAMIC_LIGHT 1
122121
#ifdef SAMPLE_DYNAMIC_LIGHT
@@ -735,38 +734,58 @@ void W3DDisplay::init( void )
735734
m_2DRender = NEW Render2DClass;
736735
DEBUG_ASSERTCRASH( m_2DRender, ("Cannot create Render2DClass") );
737736

738-
// set our default width and height and bit depth
739-
/// @todo we should set this according to options read from a file
740-
setWidth( TheGlobalData->m_xResolution );
741-
setHeight( TheGlobalData->m_yResolution );
742-
setBitDepth( W3D_DISPLAY_DEFAULT_BIT_DEPTH );
743-
744-
if( WW3D::Set_Render_Device( 0,
745-
getWidth(),
746-
getHeight(),
747-
getBitDepth(),
748-
getWindowed(),
749-
true ) != WW3D_ERROR_OK )
737+
WW3DErrorType renderDeviceError;
738+
Int attempt = 0;
739+
do
750740
{
751-
// Getting the device at the default bit depth (32) didn't work, so try
752-
// getting a 16 bit display. (Voodoo 1-3 only supported 16 bit.) jba.
753-
setBitDepth( 16 );
754-
if( WW3D::Set_Render_Device( 0,
755-
getWidth(),
756-
getHeight(),
757-
getBitDepth(),
758-
getWindowed(),
759-
true ) != WW3D_ERROR_OK )
741+
switch (attempt)
760742
{
761-
762-
WW3D::Shutdown();
763-
WWMath::Shutdown();
764-
throw ERROR_INVALID_D3D; //failed to initialize. User probably doesn't have DX 8.1
765-
DEBUG_ASSERTCRASH( 0, ("Unable to set render device\n") );
766-
return;
743+
case 0:
744+
// set our default width and height and bit depth
745+
setWidth( TheGlobalData->m_xResolution );
746+
setHeight( TheGlobalData->m_yResolution );
747+
setBitDepth( 32 );
748+
break;
749+
case 1:
750+
// Getting the device at the default bit depth (32) didn't work, so try
751+
// getting a 16 bit display. (Voodoo 1-3 only supported 16 bit.) jba.
752+
setBitDepth( 16 );
753+
break;
754+
case 2:
755+
// TheSuperHackers @bugfix xezon 11/06/2025 Now tries a safe default resolution
756+
// if the previous one did not succeed. This is unlikely to happen but is possible
757+
// if the user writes an unsupported resolution into to the Option Preferences.
758+
TheWritableGlobalData->m_xResolution = 800;
759+
TheWritableGlobalData->m_yResolution = 600;
760+
setWidth( TheGlobalData->m_xResolution );
761+
setHeight( TheGlobalData->m_yResolution );
762+
setBitDepth( 32 );
763+
break;
764+
case 3:
765+
setBitDepth( 16 );
766+
break;
767767
}
768768

769-
} // end if
769+
renderDeviceError = WW3D::Set_Render_Device(
770+
0,
771+
getWidth(),
772+
getHeight(),
773+
getBitDepth(),
774+
getWindowed(),
775+
true );
776+
777+
++attempt;
778+
}
779+
while (attempt < 4 && renderDeviceError != WW3D_ERROR_OK);
780+
781+
if (renderDeviceError != WW3D_ERROR_OK)
782+
{
783+
WW3D::Shutdown();
784+
WWMath::Shutdown();
785+
throw ERROR_INVALID_D3D; //failed to initialize. User probably doesn't have DX 8.1
786+
DEBUG_ASSERTCRASH( 0, ("Unable to set render device\n") );
787+
return;
788+
}
770789

771790
//Check if level was never set and default to setting most suitable for system.
772791
if (TheGameLODManager->getStaticLODLevel() == STATIC_GAME_LOD_UNKNOWN)

0 commit comments

Comments
 (0)