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): check every vertex and index buffer lock before writing
Olcay Seygan3d761d918fb4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex da073ac13..5a2f29508 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -383,6 +383,7 @@ found and fixed — EA's own, not port damage.**- A mission script that waits for a line of speech to finish waits the same length of time on every machine. It used to ask the sound hardware how long the file was, so a player whose sound card was not working, or was turned off, got the answer zero and walked straight through waits that everyone else sat out. That is a different game on two screens, and a replay that stops matching the machine that recorded it. The length now comes out of the file itself: measured on one line of speech, a silent machine said 0 milliseconds and a machine with sound said 3,285. Both say 3,285 now.- Laying a foundation costs less the further up the map you build. Flattening the ground under a new building scanned every row of the map from the bottom edge up to the building, threw all of them away bar the ones actually under it, and did that once per column. It works out the rows it needs now. The ground comes out identical, down to the last unit of height.- EVA announcements that were queued behind another one no longer go quiet. A request waits its turn and expires if its turn never comes, and the sum that worked out when that was could wrap round to zero, retiring the announcement on the frame it was asked for.+- Ten more places that wrote terrain, roads, bridges, trees, foundations and scorch marks into a buffer the graphics card had refused to hand over. Every one of them wrote to address zero instead, and a graphics device pulled out from under the game is all it takes; the frame is simply skipped now.- Tank tracks no longer crash the game. The renderer has to borrow the buffer it writes them into, and when that request failed, which is what a graphics device pulled out from under the game does, the tracks were written to address zero anyway. Two more of the same shape went with it: the screenshot path and the texture size lookup both used a pointer that the failing call had never filled in. Three of those texture lookups also leaked the surface they asked about, once per procedural texture, for the life of the process.- Double-clicking a menu button opens the screen once. The button stays live while the old screen animates out, so the second click started the same transition again and the screen opened twice, one copy left drawn over whatever came next and doing nothing sensible when clicked.- Double-tapping 0 jumps the camera to that group.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cppindex f2ebe44af..58dbeaae0 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp@@ -1928,10 +1928,17 @@ void BaseHeightMapRenderObjClass::updateScorches(void)m_curNumScorchIndices = 0;DX8IndexBufferClass::WriteLockClass lockIdxBuffer(m_indexScorch);UnsignedShort *ib=lockIdxBuffer.Get_Index_Array();- UnsignedShort *curIb = ib;DX8VertexBufferClass::WriteLockClass lockVtxBuffer(m_vertexScorch);VertexFormatXYZDUV1 *vb = (VertexFormatXYZDUV1*)lockVtxBuffer.Get_Vertex_Array();++ // a failed lock - a device that has gone away - hands back nothing to write into, and the+ // counts stay at zero so nothing is drawn from a buffer that was never filled+ if (ib == NULL || vb == NULL) {+ return;+ }++ UnsignedShort *curIb = ib;VertexFormatXYZDUV1 *curVb = vb;Int curScorch;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cppindex 7d117c767..702cfac37 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp@@ -344,6 +344,10 @@ Int HeightMapRenderObjClass::updateVB(DX8VertexBufferClass *pVB, char *data, IntDX8VertexBufferClass::WriteLockClass lockVtxBuffer(pVB);VERTEX_FORMAT *vbHardware = (VERTEX_FORMAT*)lockVtxBuffer.Get_Vertex_Array();+ // a failed lock - a device that has gone away - hands back nothing to copy the tile into+ if (vbHardware == NULL) {+ return 0;+ }VERTEX_FORMAT *vBase = (VERTEX_FORMAT*)data;// Note that we are building the vertex buffer data in the memory buffer, data.// At the bottom, we will copy the final vertex data for one cell into the@@ -593,6 +597,10 @@ Int HeightMapRenderObjClass::updateVBForLight(DX8VertexBufferClass *pVB, char *dDX8VertexBufferClass::WriteLockClass lockVtxBuffer(pVB);VERTEX_FORMAT *vBase = (VERTEX_FORMAT*)lockVtxBuffer.Get_Vertex_Array();+ // a failed lock - a device that has gone away - hands back nothing to light+ if (vBase == NULL) {+ return 0;+ }VERTEX_FORMAT *vb;for (j=y0; j<y1; j++)@@ -740,6 +748,10 @@ Int HeightMapRenderObjClass::updateVBForLightOptimized(DX8VertexBufferClass *pVBDX8VertexBufferClass::WriteLockClass lockVtxBuffer(pVB);VERTEX_FORMAT *vBase = (VERTEX_FORMAT*)lockVtxBuffer.Get_Vertex_Array();+ // a failed lock - a device that has gone away - hands back nothing to light+ if (vBase == NULL) {+ return 0;+ }VERTEX_FORMAT *vb;//@@ -1339,8 +1351,9 @@ Int HeightMapRenderObjClass::initHeightData(Int x, Int y, WorldHeightMap *pMap,// Fill up the IBDX8IndexBufferClass::WriteLockClass lockIdxBuffer(m_indexBuffer);UnsignedShort *ib=lockIdxBuffer.Get_Index_Array();-- for (j=0; j<(VERTEX_BUFFER_TILE_LENGTH*VERTEX_BUFFER_TILE_LENGTH*4); j+=VERTEX_BUFFER_TILE_LENGTH*4)++ // a failed lock leaves nothing to write the indices into+ for (j=0; ib != NULL && j<(VERTEX_BUFFER_TILE_LENGTH*VERTEX_BUFFER_TILE_LENGTH*4); j+=VERTEX_BUFFER_TILE_LENGTH*4){for (i=j; i<(j+VERTEX_BUFFER_TILE_LENGTH*4); i+=4) //4 vertices per 2x2 block{diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBibBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBibBuffer.cppindex ed1d594b0..ce44f2298 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBibBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBibBuffer.cpp@@ -109,6 +109,10 @@ void W3DBibBuffer::loadBibsInVertexAndIndexBuffers(void)DX8VertexBufferClass::WriteLockClass lockVtxBuffer(m_vertexBib, D3DLOCK_DISCARD);vb=(VertexFormatXYZDUV1*)lockVtxBuffer.Get_Vertex_Array();ib = lockIdxBuffer.Get_Index_Array();+ // a failed lock - a device that has gone away - hands back nothing to write into+ if (vb == NULL || ib == NULL) {+ return;+ }// Add to the index buffer & vertex buffer.UnsignedShort *curIb = ib;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cppindex de735ea17..30cd03a40 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp@@ -701,6 +701,11 @@ void W3DBridgeBuffer::loadBridgesInVertexAndIndexBuffers(RefRenderObjListIteratoDX8VertexBufferClass::WriteLockClass lockVtxBuffer(m_vertexBridge, D3DLOCK_DISCARD);vb=(VertexFormatXYZNDUV1*)lockVtxBuffer.Get_Vertex_Array();ib = lockIdxBuffer.Get_Index_Array();+ // a failed lock - a device that has gone away - hands back nothing to write into, and the+ // counts stay at zero so nothing is drawn from a buffer that was never filled+ if (vb == NULL || ib == NULL) {+ return;+ }// UnsignedShort *curIb = ib;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DCustomEdging.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DCustomEdging.cppindex 09cd429da..4874cb1fa 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DCustomEdging.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DCustomEdging.cpp@@ -130,6 +130,11 @@ void W3DCustomEdging::loadEdgingsInVertexAndIndexBuffers(WorldHeightMap *pMap, IDX8VertexBufferClass::WriteLockClass lockVtxBuffer(m_vertexEdging);vb=(VertexFormatXYZDUV2*)lockVtxBuffer.Get_Vertex_Array();ib = lockIdxBuffer.Get_Index_Array();+ // a failed lock - a device that has gone away - hands back nothing to write into, and the+ // counts stay at zero so nothing is drawn from a buffer that was never filled+ if (vb == NULL || ib == NULL) {+ return;+ }UnsignedShort *curIb = ib;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cppindex 58e13045c..7ce1f7499 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp@@ -240,6 +240,8 @@ void W3DDebugIcons::Render(RenderInfoClass & rinfo)if (!vb) return;UnsignedShort *ib=lockib.Get_Index_Array();+ if (!ib) return; // the vertex lock is checked just above; this one was not+UnsignedShort *curIb = ib;// VertexFormatXYZNDUV2 *curVb = vb;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cppindex 6a9d0f217..550bb1e6a 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp@@ -1243,6 +1243,12 @@ void W3DRoadBuffer::loadRoadsInVertexAndIndexBuffers()DX8VertexBufferClass::WriteLockClass lockVtxBuffer(m_roadTypes[m_curRoadType].getVB(), s_dynamic?D3DLOCK_DISCARD:0);vb=(VertexFormatXYZDUV1*)lockVtxBuffer.Get_Vertex_Array();ib = lockIdxBuffer.Get_Index_Array();+ // a failed lock - a device that has gone away - hands back nothing to write into+ if (vb == NULL || ib == NULL) {+ m_roadTypes[m_curRoadType].setNumVertices(0);+ m_roadTypes[m_curRoadType].setNumIndices(0);+ return;+ }// Add to the index buffer & vertex buffer.Int curRoad;@@ -1327,6 +1333,10 @@ void W3DRoadBuffer::loadLitRoadsInVertexAndIndexBuffers(RefRenderObjListIteratorDX8VertexBufferClass::WriteLockClass lockVtxBuffer(m_roadTypes[m_curRoadType].getVB());vb=(VertexFormatXYZDUV1*)lockVtxBuffer.Get_Vertex_Array();ib = lockIdxBuffer.Get_Index_Array();+ // a failed lock - a device that has gone away - hands back nothing to write into+ if (vb == NULL || ib == NULL) {+ return;+ }// Add to the index buffer & vertex buffer.Int curRoad;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cppindex 2a33f7848..d2f3c82d2 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp@@ -740,6 +740,10 @@ void W3DTreeBuffer::loadTreesInVertexAndIndexBuffers(RefRenderObjListIterator *p#endifvb=(VertexFormatXYZNDUV1*)lockVtxBuffer.Get_Vertex_Array();ib = lockIdxBuffer.Get_Index_Array();+ // a failed lock - a device that has gone away - hands back nothing to write into+ if (vb == NULL || ib == NULL) {+ continue;+ }// Add to the index buffer & vertex buffer.Vector2 lookAtVector(m_cameraLookAtVector.X, m_cameraLookAtVector.Y);lookAtVector.Normalize();@@ -1010,6 +1014,15 @@ void W3DTreeBuffer::updateVertexBuffer(void)#endifvb=(VertexFormatXYZNDUV1*)lockVtxBuffer.Get_Vertex_Array();+ //+ // The lock fails when the device has gone out from under us, and everything below writes+ // through this pointer without looking. Same shape as the tank tracks flush: give up on+ // this buffer, the next frame will push the trees aside again.+ //+ if (vb == NULL) {+ continue;+ }+VertexFormatXYZNDUV1 *curVb;Int curTree;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cppindex fde292d3b..ba2482cfd 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp@@ -155,6 +155,14 @@ void W3DRenderObjectSnapshot::update(RenderObjClass *robj, DrawableInfo *drawInf// ------------------------------------------------------------------------------------------------void W3DRenderObjectSnapshot::addToScene(void){+ //+ // Ghost objects are logic-side bookkeeping - what a player remembers of ground now under fog -+ // and they get built on a run that has no scene to put them in. A headless replay playback is+ // the way to see it: the logic makes the snapshot, this puts it in a scene that does not exist.+ //+ if (W3DDisplay::m_3DScene == NULL || m_robj == NULL)+ return;+((SimpleSceneClass *)W3DDisplay::m_3DScene)->Add_Render_Object(m_robj);}@@ -549,7 +557,8 @@ void W3DGhostObject::removeFromScene(int playerIndex)while (snap){- snap->m_robj->Remove();+ if (snap->m_robj)+ snap->m_robj->Remove();snap=snap->m_next;}}@@ -559,11 +568,16 @@ void W3DGhostObject::removeFromScene(int playerIndex)// ------------------------------------------------------------------------------------------------void W3DGhostObject::addToScene(int playerIndex){+ // no scene to add to on a run with no picture - see W3DRenderObjectSnapshot::addToScene above+ if (W3DDisplay::m_3DScene == NULL)+ return;+W3DRenderObjectSnapshot *snap=m_parentSnapshots[playerIndex];while (snap){- ((SimpleSceneClass *)W3DDisplay::m_3DScene)->Add_Render_Object(snap->m_robj);+ if (snap->m_robj)+ ((SimpleSceneClass *)W3DDisplay::m_3DScene)->Add_Render_Object(snap->m_robj);snap=snap->m_next;}}