@@ -116,7 +116,10 @@ static void drawFramerateBar(void);
116
116
#endif
117
117
118
118
// DEFINE AND ENUMS ///////////////////////////////////////////////////////////
119
- #define W3D_DISPLAY_DEFAULT_BIT_DEPTH 32
119
+ #define DEFAULT_DISPLAY_BIT_DEPTH 32
120
+ #define MIN_DISPLAY_BIT_DEPTH 16
121
+ #define MIN_DISPLAY_RESOLUTION_X 800
122
+ #define MIN_DISPLAY_RESOLUTION_Y 600
120
123
121
124
#define no_SAMPLE_DYNAMIC_LIGHT 1
122
125
#ifdef SAMPLE_DYNAMIC_LIGHT
@@ -478,9 +481,6 @@ W3DDisplay::~W3DDisplay()
478
481
479
482
} // end ~W3DDisplay
480
483
481
- #define MIN_DISPLAY_RESOLUTION_X 800
482
- #define MIN_DISPLAY_RESOLUTOIN_Y 600
483
-
484
484
485
485
Bool IS_FOUR_BY_THREE_ASPECT ( Real x, Real y )
486
486
{
@@ -735,38 +735,73 @@ void W3DDisplay::init( void )
735
735
m_2DRender = NEW Render2DClass;
736
736
DEBUG_ASSERTCRASH ( m_2DRender, (" Cannot create Render2DClass" ) );
737
737
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 )
738
+ WW3DErrorType renderDeviceError;
739
+ Int attempt = 0 ;
740
+ do
750
741
{
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 )
742
+ switch (attempt)
760
743
{
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 ;
744
+ case 0 :
745
+ {
746
+ // set our default width and height and bit depth
747
+ setWidth ( TheGlobalData->m_xResolution );
748
+ setHeight ( TheGlobalData->m_yResolution );
749
+ setBitDepth ( DEFAULT_DISPLAY_BIT_DEPTH );
750
+ break ;
751
+ }
752
+ case 1 :
753
+ {
754
+ // Getting the device at the default bit depth (32) didn't work, so try
755
+ // getting a 16 bit display. (Voodoo 1-3 only supported 16 bit.) jba.
756
+ setBitDepth ( MIN_DISPLAY_BIT_DEPTH );
757
+ break ;
758
+ }
759
+ case 2 :
760
+ {
761
+ // TheSuperHackers @bugfix xezon 11/06/2025 Now tries a safe default resolution
762
+ // if the custom resolution did not succeed. This is unlikely to happen but is possible
763
+ // if the user writes an unsupported resolution in the Option Preferences or if the
764
+ // graphics adapter does not support the minimum display resolution to begin with.
765
+ Int xres = MIN_DISPLAY_RESOLUTION_X;
766
+ Int yres = MIN_DISPLAY_RESOLUTION_Y;
767
+ Int bitDepth = DEFAULT_DISPLAY_BIT_DEPTH;
768
+ Int displayModeCount = getDisplayModeCount ();
769
+ Int displayModeIndex = 0 ;
770
+ for (; displayModeIndex < displayModeCount; ++displayModeIndex)
771
+ {
772
+ getDisplayModeDescription (displayModeIndex, &xres, &yres, &bitDepth);
773
+ if (xres * yres >= MIN_DISPLAY_RESOLUTION_X * MIN_DISPLAY_RESOLUTION_Y)
774
+ break ; // Is good enough. Use it.
775
+ }
776
+ TheWritableGlobalData->m_xResolution = xres;
777
+ TheWritableGlobalData->m_yResolution = yres;
778
+ setWidth ( xres );
779
+ setHeight ( yres );
780
+ setBitDepth ( bitDepth );
781
+ break ;
782
+ }
767
783
}
768
784
769
- } // end if
785
+ renderDeviceError = WW3D::Set_Render_Device (
786
+ 0 ,
787
+ getWidth (),
788
+ getHeight (),
789
+ getBitDepth (),
790
+ getWindowed (),
791
+ true );
792
+
793
+ ++attempt;
794
+ }
795
+ while (attempt < 3 && renderDeviceError != WW3D_ERROR_OK);
796
+
797
+ if (renderDeviceError != WW3D_ERROR_OK)
798
+ {
799
+ WW3D::Shutdown ();
800
+ WWMath::Shutdown ();
801
+ throw ERROR_INVALID_D3D; // failed to initialize. User probably doesn't have DX 8.1
802
+ DEBUG_ASSERTCRASH ( 0 , (" Unable to set render device\n " ) );
803
+ return ;
804
+ }
770
805
771
806
// Check if level was never set and default to setting most suitable for system.
772
807
if (TheGameLODManager->getStaticLODLevel () == STATIC_GAME_LOD_UNKNOWN)
0 commit comments