Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(w3ddevice): skip shadow buffers the device refused after a reset
Olcay Seygand41cff32cb82
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 358eb9ea7..4e62b7d7c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1342,6 +1342,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- Selling with more than one building selected no longer takes the game down. Each building that goes up for sale is taken out of the selection, and that rebuilt the group the sell order was still working through, so the second building was read from memory that had already been handed back. A player lost a match an hour in this way.- A machine whose graphics stack faults while the Direct3D 11 picture is being set up starts the game anyway, on the Direct3D 9 picture. A player's report showed the fault happening inside Windows' own graphics library, before the game got an answer back, and it ended in "Uncaught Exception during initialization". An overlay hooking the graphics calls or a stray dxgi.dll in the game folder is the usual cause. Until now the only way past it was typing -d3d9.- A campaign mission could crash on its very first frame with the Direct3D 11 picture on, if the screen had been reset before it by an alt-tab or a change on the display options page. The reset threw some textures away, the new picture kept drawing with them, and the first water reflection of the next map read freed memory. A reset now clears every texture from the new picture as well as the old one.+- Changing the resolution in fullscreen could crash the game the moment you pressed Accept, with the Direct3D 11 picture on. The screen reset asks the graphics card for the memory the ground shadows are drawn into, and when the card refused, the next frame wrote into memory that was never handed over. A player on an RTX 5080 met it on v2.4.0. Now the ground shadows sit out until the next reset, and the game keeps running.- The opening movies froze on their first frame with that picture on. A movie writes a new image every frame into a texture the copy had already taken.- Opening Single Player could take the game down a quarter of a second in, as the buttons flashed in. The menu's animation list names a Custom Mission button that only the 1.04 patch's main menu has, and on an install whose menu lacks it, every step of the flash skipped the missing button except one, which tried to draw it. That step skips it now too.- A skirmish against the computer could crash when a fresh unit joined one of its teams. The newcomer copies what a teammate is doing, and when that teammate was following a road the map had drawn for it, the newcomer got the order without the road and the game fell over looking for its first stop. It now gets the road as well, and a unit handed that order with no road at all gives it up instead.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cppindex 8e6cfc3e3..637bb16aa 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp@@ -304,32 +304,45 @@ Bool W3DProjectedShadowManager::ReAcquireResources(void)DEBUG_ASSERTCRASH(m_pDev, ("Trying to ReAquireResources on W3DProjectedShadowManager without device"));DEBUG_ASSERTCRASH(shadowDecalIndexBufferD3D == NULL && shadowDecalIndexBufferD3D == NULL, ("ReAquireResources not released in W3DProjectedShadowManager"));- if (Render_Failed(m_pDev->CreateIndexBuffer+ //The result is logged because a failure here is what leaves the decal buffers null after a reset,+ //and which of lost device, video memory or a refused call it was is not something the code can+ //tell afterwards.+ RenderResult hr = m_pDev->CreateIndexBuffer(- SHADOW_DECAL_INDEX_SIZE*sizeof(WORD),- D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,- D3DFMT_INDEX16,+ SHADOW_DECAL_INDEX_SIZE*sizeof(WORD),+ D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,+ D3DFMT_INDEX16,D3DPOOL_DEFAULT,&shadowDecalIndexBufferD3D,NULL // pSharedHandle, D3D9's extra parameter, reserved and always null- )))+ );+ if (Render_Failed(hr))+ {+ DEBUG_LOG(("SHADOW DECAL BUFFERS: index buffer refused, 0x%08X, cooperative level 0x%08X\n",+ (UnsignedInt)hr, (UnsignedInt)m_pDev->TestCooperativeLevel()));return FALSE;+ }shadowDecalIndexTwin = Direct3D11_Twin_Index_Buffer(SHADOW_DECAL_INDEX_SIZE*sizeof(WORD), true);if (shadowDecalVertexBufferD3D == NULL){ // Create vertex buffer- if (Render_Failed(m_pDev->CreateVertexBuffer+ hr = m_pDev->CreateVertexBuffer(SHADOW_DECAL_VERTEX_SIZE*sizeof(SHADOW_DECAL_VERTEX),- D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,+ D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,0,D3DPOOL_DEFAULT,&shadowDecalVertexBufferD3D,NULL // pSharedHandle, D3D9's extra parameter, reserved and always null- )))+ );+ if (Render_Failed(hr))+ {+ DEBUG_LOG(("SHADOW DECAL BUFFERS: vertex buffer refused, 0x%08X, cooperative level 0x%08X\n",+ (UnsignedInt)hr, (UnsignedInt)m_pDev->TestCooperativeLevel()));return FALSE;+ }shadowDecalVertexTwin = Direct3D11_Twin_Vertex_Buffer(SHADOW_DECAL_VERTEX_SIZE*sizeof(SHADOW_DECAL_VERTEX), true);@@ -412,6 +425,9 @@ Int W3DProjectedShadowManager::renderProjectedTerrainShadow(W3DProjectedShadow *if (!m_pDev) return 0;+ //the volumetric manager's streaming buffers, null when its ReAcquireResources was refused (see queueDecal)+ if (shadowVertexBufferD3D == NULL || shadowIndexBufferD3D == NULL) return 0;+//Get terrain cell index for area with shadowInt startX=REAL_TO_INT_FLOOR(((cx - dx)*mapScaleInv));Int endX=REAL_TO_INT_CEIL(((cx + dx)*mapScaleInv));@@ -916,6 +932,12 @@ void W3DProjectedShadowManager::queueDecal(W3DProjectedShadow *shadow, Bool sunCRenderObjClass *robj=shadow->m_robj;Real layerHeight=0;+ //ReAcquireResources leaves these null when the device refuses the allocation after a reset (it+ //logs SHADOW DECAL BUFFERS with the HRESULT). A v2.4.0 player locked the null one right after a+ //resolution change; without them there is no decal to draw this frame.+ if (shadowDecalVertexBufferD3D == NULL || shadowDecalIndexBufferD3D == NULL)+ return;+if (TheTerrainRenderObject){LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();@@ -1348,6 +1370,10 @@ void W3DProjectedShadowManager::queueSimpleDecal(W3DProjectedShadow *shadow)Vector3 uVector,vVector;Coord3D normal;+ //see queueDecal+ if (shadowDecalVertexBufferD3D == NULL || shadowDecalIndexBufferD3D == NULL)+ return;+if (TheTerrainRenderObject){LPDIRECT3DDEVICE9 m_pDev=DX8Wrapper::_Get_D3D_Device();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cppindex ae146df11..9d469af66 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp@@ -1538,6 +1538,12 @@ void W3DVolumetricShadow::RenderVolume(Int meshIndex, Int lightIndex)HLodClass *hlod=(HLodClass *)m_robj;MeshClass *mesh=NULL;+ //RenderDynamicMeshVolume and RenderMeshVolumeBounds lock these, and ReAcquireResources leaves+ //them null when the device refuses the allocation after a reset (it logs SHADOW VOLUME BUFFERS).+ //The projected decals locked their own null buffer that way after a resolution change in v2.4.0.+ if (shadowVertexBufferD3D == NULL || shadowIndexBufferD3D == NULL)+ return;+Int meshRobjIndex=m_geometry->getMesh(meshIndex)->m_meshRobjIndex;if (meshRobjIndex >= 0)@@ -4766,32 +4772,43 @@ Bool W3DVolumetricShadowManager::ReAcquireResources(void)DEBUG_ASSERTCRASH(m_pDev, ("Trying to ReAquireResources on W3DVolumetricShadowManager without device"));- if (Render_Failed(m_pDev->CreateIndexBuffer+ // Logged for the reason W3DProjectedShadowManager::ReAcquireResources gives.+ RenderResult hr = m_pDev->CreateIndexBuffer(- SHADOW_INDEX_SIZE*sizeof(WORD),- D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,- D3DFMT_INDEX16,+ SHADOW_INDEX_SIZE*sizeof(WORD),+ D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,+ D3DFMT_INDEX16,D3DPOOL_DEFAULT,&shadowIndexBufferD3D,NULL // pSharedHandle, D3D9's extra parameter, reserved and always null- )))+ );+ if (Render_Failed(hr))+ {+ DEBUG_LOG(("SHADOW VOLUME BUFFERS: index buffer refused, 0x%08X, cooperative level 0x%08X\n",+ (UnsignedInt)hr, (UnsignedInt)m_pDev->TestCooperativeLevel()));return FALSE;+ }shadowIndexTwin = Direct3D11_Twin_Index_Buffer(SHADOW_INDEX_SIZE*sizeof(WORD), true);if (shadowVertexBufferD3D == NULL){ // Create vertex buffer- if (Render_Failed(m_pDev->CreateVertexBuffer+ hr = m_pDev->CreateVertexBuffer(SHADOW_VERTEX_SIZE*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX),- D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,+ D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,0,D3DPOOL_DEFAULT,&shadowVertexBufferD3D,NULL // pSharedHandle, D3D9's extra parameter, reserved and always null- )))+ );+ if (Render_Failed(hr))+ {+ DEBUG_LOG(("SHADOW VOLUME BUFFERS: vertex buffer refused, 0x%08X, cooperative level 0x%08X\n",+ (UnsignedInt)hr, (UnsignedInt)m_pDev->TestCooperativeLevel()));return FALSE;+ }shadowVertexTwin = Direct3D11_Twin_Vertex_Buffer(SHADOW_VERTEX_SIZE*sizeof(SHADOW_DYNAMIC_VOLUME_VERTEX), true);