Skip to content

Commit ff1baff

Browse files
authored
bugfix(dx8): Improve display mode transition reliability (TheSuperHackers#2539)
1. Defer Render2D resolution update until after successful D3D reset 2. Snapshot current mode before Set_Device_Resolution for correct rollback 3. Fix fullscreen window failing to cover desktop by removing SWP_NOSIZE/NOMOVE 4. Remove duplicate D3DInterface release block in Shutdown
1 parent 164db08 commit ff1baff

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ void W3DDisplay::setGamma(Real gamma, Real bright, Real contrast, Bool calibrate
491491
//=============================================================================
492492
Bool W3DDisplay::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt bitdepth, Bool windowed )
493493
{
494+
const UnsignedInt oldWidth = getWidth();
495+
const UnsignedInt oldHeight = getHeight();
496+
const UnsignedInt oldBitDepth = getBitDepth();
497+
const Bool oldWindowed = getWindowed();
498+
494499
if (WW3D_ERROR_OK == WW3D::Set_Device_Resolution(xres,yres,bitdepth,windowed,true))
495500
{
496501
Render2DClass::Set_Screen_Resolution(RectClass(0, 0, xres, yres));
@@ -499,9 +504,9 @@ Bool W3DDisplay::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt
499504
}
500505

501506
//set back to the original mode.
502-
WW3D::Set_Device_Resolution(getWidth(),getHeight(),getBitDepth(),getWindowed(), true);
503-
Render2DClass::Set_Screen_Resolution(RectClass(0, 0, getWidth(),getHeight()));
504-
Display::setDisplayMode(getWidth(),getHeight(),getBitDepth(), getWindowed());
507+
WW3D::Set_Device_Resolution(oldWidth, oldHeight, oldBitDepth, oldWindowed, true);
508+
Render2DClass::Set_Screen_Resolution(RectClass(0, 0, oldWidth, oldHeight));
509+
Display::setDisplayMode(oldWidth, oldHeight, oldBitDepth, oldWindowed);
505510
return FALSE; //did not change to a new mode.
506511
}
507512

Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,6 @@ void DX8Wrapper::Shutdown()
349349
}
350350
}
351351

352-
if (D3DInterface) {
353-
UINT newRefCount=D3DInterface->Release();
354-
D3DInterface=nullptr;
355-
}
356-
357352
if (D3D8Lib) {
358353
FreeLibrary(D3D8Lib);
359354
D3D8Lib = nullptr;
@@ -830,7 +825,7 @@ void DX8Wrapper::Resize_And_Position_Window()
830825
// Resize the window to fit this resolution
831826
if (!IsWindowed)
832827
{
833-
::SetWindowPos(_Hwnd, HWND_TOPMOST, 0, 0, width, height, SWP_NOSIZE | SWP_NOMOVE);
828+
::SetWindowPos(_Hwnd, HWND_TOPMOST, 0, 0, width, height, 0);
834829

835830
DEBUG_LOG(("Window resized to w:%d h:%d", width, height));
836831
}
@@ -883,9 +878,6 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
883878
if (width != -1) ResolutionWidth = width;
884879
if (height != -1) ResolutionHeight = height;
885880

886-
// Initialize Render2DClass Screen Resolution
887-
Render2DClass::Set_Screen_Resolution( RectClass( 0, 0, ResolutionWidth, ResolutionHeight ) );
888-
889881
if (bits != -1) BitDepth = bits;
890882
if (windowed != -1) IsWindowed = (windowed != 0);
891883
DX8Wrapper_IsWindowed = IsWindowed;
@@ -1053,6 +1045,11 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
10531045

10541046
WWDEBUG_SAY(("Reset/Create_Device done, reset_device=%d, restore_assets=%d", reset_device, restore_assets));
10551047

1048+
if (ret)
1049+
{
1050+
Render2DClass::Set_Screen_Resolution( RectClass( 0, 0, ResolutionWidth, ResolutionHeight ) );
1051+
}
1052+
10561053
return ret;
10571054
}
10581055

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ void W3DDisplay::setGamma(Real gamma, Real bright, Real contrast, Bool calibrate
541541
//=============================================================================
542542
Bool W3DDisplay::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt bitdepth, Bool windowed )
543543
{
544+
const UnsignedInt oldWidth = getWidth();
545+
const UnsignedInt oldHeight = getHeight();
546+
const UnsignedInt oldBitDepth = getBitDepth();
547+
const Bool oldWindowed = getWindowed();
548+
544549
if (WW3D_ERROR_OK == WW3D::Set_Device_Resolution(xres,yres,bitdepth,windowed,true))
545550
{
546551
Render2DClass::Set_Screen_Resolution(RectClass(0, 0, xres, yres));
@@ -549,9 +554,9 @@ Bool W3DDisplay::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt
549554
}
550555

551556
//set back to the original mode.
552-
WW3D::Set_Device_Resolution(getWidth(),getHeight(),getBitDepth(),getWindowed(), true);
553-
Render2DClass::Set_Screen_Resolution(RectClass(0, 0, getWidth(),getHeight()));
554-
Display::setDisplayMode(getWidth(),getHeight(),getBitDepth(), getWindowed());
557+
WW3D::Set_Device_Resolution(oldWidth, oldHeight, oldBitDepth, oldWindowed, true);
558+
Render2DClass::Set_Screen_Resolution(RectClass(0, 0, oldWidth, oldHeight));
559+
Display::setDisplayMode(oldWidth, oldHeight, oldBitDepth, oldWindowed);
555560
return FALSE; //did not change to a new mode.
556561
}
557562

GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,6 @@ void DX8Wrapper::Shutdown()
353353
}
354354
}
355355

356-
if (D3DInterface) {
357-
UINT newRefCount=D3DInterface->Release();
358-
D3DInterface=nullptr;
359-
}
360-
361356
if (D3D8Lib) {
362357
FreeLibrary(D3D8Lib);
363358
D3D8Lib = nullptr;
@@ -896,7 +891,7 @@ void DX8Wrapper::Resize_And_Position_Window()
896891
// Resize the window to fit this resolution
897892
if (!IsWindowed)
898893
{
899-
::SetWindowPos(_Hwnd, HWND_TOPMOST, 0, 0, width, height, SWP_NOSIZE | SWP_NOMOVE);
894+
::SetWindowPos(_Hwnd, HWND_TOPMOST, 0, 0, width, height, 0);
900895

901896
DEBUG_LOG(("Window resized to w:%d h:%d", width, height));
902897
}
@@ -949,9 +944,6 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
949944
if (width != -1) ResolutionWidth = width;
950945
if (height != -1) ResolutionHeight = height;
951946

952-
// Initialize Render2DClass Screen Resolution
953-
Render2DClass::Set_Screen_Resolution( RectClass( 0, 0, ResolutionWidth, ResolutionHeight ) );
954-
955947
if (bits != -1) BitDepth = bits;
956948
if (windowed != -1) IsWindowed = (windowed != 0);
957949
DX8Wrapper_IsWindowed = IsWindowed;
@@ -1120,6 +1112,11 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int
11201112

11211113
WWDEBUG_SAY(("Reset/Create_Device done, reset_device=%d, restore_assets=%d", reset_device, restore_assets));
11221114

1115+
if (ret)
1116+
{
1117+
Render2DClass::Set_Screen_Resolution( RectClass( 0, 0, ResolutionWidth, ResolutionHeight ) );
1118+
}
1119+
11231120
return ret;
11241121
}
11251122

0 commit comments

Comments
 (0)