Skip to content

Commit 44002f5

Browse files
bugfix(dx8wrapper): Prevent crash when getting depth buffer on lost device
1 parent 6266009 commit 44002f5

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,7 +3324,11 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default
33243324
//
33253325
// We'll need the depth buffer later...
33263326
//
3327-
if (DefaultDepthBuffer == nullptr)
3327+
// GO_CHANGE
3328+
// Guard against calling GetDepthStencilSurface on a lost/invalid device.
3329+
// The D3D9-to-D3D12 translation layer may access freed GPU memory if the
3330+
// device is in a lost state, causing an EXCEPTION_ACCESS_VIOLATION_READ crash.
3331+
if (DefaultDepthBuffer == nullptr && !IsDeviceLost)
33283332
{
33293333
// IDirect3DSurface8 *depth_buffer = nullptr;
33303334
DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer));
@@ -3452,7 +3456,11 @@ void DX8Wrapper::Set_Render_Target
34523456
//
34533457
// We'll need the depth buffer later...
34543458
//
3455-
if (DefaultDepthBuffer == nullptr)
3459+
// GO_CHANGE
3460+
// Guard against calling GetDepthStencilSurface on a lost/invalid device.
3461+
// The D3D9-to-D3D12 translation layer may access freed GPU memory if the
3462+
// device is in a lost state, causing an EXCEPTION_ACCESS_VIOLATION_READ crash.
3463+
if (DefaultDepthBuffer == nullptr && !IsDeviceLost)
34563464
{
34573465
// IDirect3DSurface8 *depth_buffer = nullptr;
34583466
DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer));

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,7 +3600,11 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default
36003600
//
36013601
// We'll need the depth buffer later...
36023602
//
3603-
if (DefaultDepthBuffer == nullptr)
3603+
// GO_CHANGE
3604+
// Guard against calling GetDepthStencilSurface on a lost/invalid device.
3605+
// The D3D9-to-D3D12 translation layer may access freed GPU memory if the
3606+
// device is in a lost state, causing an EXCEPTION_ACCESS_VIOLATION_READ crash.
3607+
if (DefaultDepthBuffer == nullptr && !IsDeviceLost)
36043608
{
36053609
// IDirect3DSurface8 *depth_buffer = nullptr;
36063610
DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer));
@@ -3728,7 +3732,11 @@ void DX8Wrapper::Set_Render_Target
37283732
//
37293733
// We'll need the depth buffer later...
37303734
//
3731-
if (DefaultDepthBuffer == nullptr)
3735+
// GO_CHANGE
3736+
// Guard against calling GetDepthStencilSurface on a lost/invalid device.
3737+
// The D3D9-to-D3D12 translation layer may access freed GPU memory if the
3738+
// device is in a lost state, causing an EXCEPTION_ACCESS_VIOLATION_READ crash.
3739+
if (DefaultDepthBuffer == nullptr && !IsDeviceLost)
37323740
{
37333741
// IDirect3DSurface8 *depth_buffer = nullptr;
37343742
DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer));

0 commit comments

Comments
 (0)