Skip to content

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.

fix(w3ddevice): drop a tree whose model will not load

Olcay Seyganefb3645e2fa2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 015c4607d..91fe360ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -878,6 +878,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Starting the game from the folder the zip was unpacked to says what is wrong. None of Zero Hour's own files are in that folder, so the first one the game asked for was missing, and the box that came up blamed viruses and overheated hardware. It now names the folder it looked in and tells you to run install.bat.
- A machine that once had Generals installed from a disc or The First Decade, and later removed it, no longer loses the original game's files. The old install leaves its address behind in Windows, the game trusted it over the copy Steam keeps beside Zero Hour, and the main menu came up over magenta water and black hills. A folder that turns out to be empty is passed over now.
- Buying both games on Steam is enough. Steam writes nothing to Windows saying where it put them and installs the two side by side in their own folders, so the game had no way of finding the original one unless you had copied its files across by hand: a fresh install of both came up on a magenta main menu with most of the sound effects missing. The folder next to Zero Hour's is searched now. When the original game's files really are nowhere, a box names the folder to put them in, rather than leaving you to read a pink menu.
+- A tank driving into a wood no longer takes the game down. On an install missing the original game's artwork, trees whose model could not be loaded were still planted on the map, half set up, and the first unit that drove close enough to shove one aside read from the half of them that was never filled in. One missing folder was costing a crash in the middle of a match as well as a pink menu. A tree whose model will not load is simply left out.
- Nor can a map handed to you over the network, however long a name the other machine gives it.
- An order too big for one packet arrives in pieces, and a piece that claims to belong outside the order is dropped instead of landing there.
- A chat line too long for a packet is dropped rather than arriving as a different, shorter line.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
index d28936c32..30b94ccab 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
@@ -1427,11 +1427,19 @@ void W3DTreeBuffer::removeTreesForConstruction(const Coord3D* pos, const Geometr
//=============================================================================
/** Adds a type of tree (model & texture). */
//=============================================================================
+//
+// Every failure below returns -1, which is what addTree's "if (treeType<0)" already reads as "do
+// not add this tree". They used to return 0: a valid index, and when the failing type was the
+// first one on the map, an index at a slot whose m_data was still null. The tree was added anyway
+// and put in the area partition, and the first unit to drive within its radius dereferenced that
+// null in unitMoved - the access violation at 0x10 (m_framesToMoveOutward) a player hit with the
+// base game's W3D.big not loaded, so every tree model on the map was missing.
+//=============================================================================
Int W3DTreeBuffer::addTreeType(const W3DTreeDrawModuleData *data)
{
if (m_numTreeTypes>=MAX_TYPES) {
DEBUG_CRASH(("Too many kinds of trees in map. Reduce kinds of trees, or raise tree limit. jba."));
- return 0;
+ return -1;
}
m_needToUpdateTexture = true;
@@ -1441,7 +1449,7 @@ Int W3DTreeBuffer::addTreeType(const W3DTreeDrawModuleData *data)
if (robj==NULL) {
DEBUG_CRASH(("Unable to find model for tree %s\n", data->m_modelName.str()));
- return 0;
+ return -1;
}
AABoxClass box;
@@ -1450,19 +1458,34 @@ Int W3DTreeBuffer::addTreeType(const W3DTreeDrawModuleData *data)
if (robj->Class_ID() == RenderObjClass::CLASSID_HLOD) {
RenderObjClass *hlod = robj;
robj = hlod->Get_Sub_Object(0);
+ // An HLOD with nothing in it answers this with NULL, and the bone transform below read
+ // straight off it. The model comes out of a big file the player supplies, so an empty one
+ // is a thing that arrives rather than a thing that cannot happen.
+ if (robj==NULL) {
+ DEBUG_CRASH(("Tree %s is an empty hierarchy.\n", data->m_modelName.str()));
+ REF_PTR_RELEASE(hlod);
+ return -1;
+ }
const Matrix3D xfm = robj->Get_Bone_Transform(0);
xfm.Get_Translation(&offset);
REF_PTR_RELEASE(hlod);
}
- if (robj->Class_ID() == RenderObjClass::CLASSID_MESH)
+ if (robj->Class_ID() == RenderObjClass::CLASSID_MESH) {
m_treeTypes[m_numTreeTypes].m_mesh = (MeshClass*)robj;
+ } else {
+ // m_mesh takes over the reference Create_Render_Obj (or Get_Sub_Object) handed us; every
+ // other class walks out of this function and has to give it back. A map full of trees the
+ // asset manager answers with the wrong class leaked one render object per tree, because
+ // addTreeType is called again for every instance of a type that never got added.
+ REF_PTR_RELEASE(robj);
+ }
DEBUG_LOG(("TREETYPE %d: %s\n", m_numTreeTypes, data->m_modelName.str()));
if (m_treeTypes[m_numTreeTypes].m_mesh==NULL) {
DEBUG_CRASH(("Tree %s is not simple mesh. Tell artist to re-export. Don't Ignore!!!\n", data->m_modelName.str()));
- return 0;
+ return -1;
}
Int numVertex = m_treeTypes[m_numTreeTypes].m_mesh->Peek_Model()->Get_Vertex_Count();