diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 2010594f043..46f82157465 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -3324,7 +3324,11 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default // // We'll need the depth buffer later... // - if (DefaultDepthBuffer == nullptr) + // GO_CHANGE + // Guard against calling GetDepthStencilSurface on a lost/invalid device. + // The D3D9-to-D3D12 translation layer may access freed GPU memory if the + // device is in a lost state, causing an EXCEPTION_ACCESS_VIOLATION_READ crash. + if (DefaultDepthBuffer == nullptr && !IsDeviceLost) { // IDirect3DSurface8 *depth_buffer = nullptr; DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer)); @@ -3452,7 +3456,11 @@ void DX8Wrapper::Set_Render_Target // // We'll need the depth buffer later... // - if (DefaultDepthBuffer == nullptr) + // GO_CHANGE + // Guard against calling GetDepthStencilSurface on a lost/invalid device. + // The D3D9-to-D3D12 translation layer may access freed GPU memory if the + // device is in a lost state, causing an EXCEPTION_ACCESS_VIOLATION_READ crash. + if (DefaultDepthBuffer == nullptr && !IsDeviceLost) { // IDirect3DSurface8 *depth_buffer = nullptr; DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer)); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 6deec90ab90..0aa1e62d792 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -3600,7 +3600,11 @@ DX8Wrapper::Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default // // We'll need the depth buffer later... // - if (DefaultDepthBuffer == nullptr) + // GO_CHANGE + // Guard against calling GetDepthStencilSurface on a lost/invalid device. + // The D3D9-to-D3D12 translation layer may access freed GPU memory if the + // device is in a lost state, causing an EXCEPTION_ACCESS_VIOLATION_READ crash. + if (DefaultDepthBuffer == nullptr && !IsDeviceLost) { // IDirect3DSurface8 *depth_buffer = nullptr; DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer)); @@ -3728,7 +3732,11 @@ void DX8Wrapper::Set_Render_Target // // We'll need the depth buffer later... // - if (DefaultDepthBuffer == nullptr) + // GO_CHANGE + // Guard against calling GetDepthStencilSurface on a lost/invalid device. + // The D3D9-to-D3D12 translation layer may access freed GPU memory if the + // device is in a lost state, causing an EXCEPTION_ACCESS_VIOLATION_READ crash. + if (DefaultDepthBuffer == nullptr && !IsDeviceLost) { // IDirect3DSurface8 *depth_buffer = nullptr; DX8CALL(GetDepthStencilSurface (&DefaultDepthBuffer));