FIX: Assumption in terrData.h breaks some terrain mods
by Fenrir Wolf · in Torque Game Engine · 08/18/2004 (12:18 am) · 5 replies
A "bug" in terrData.h will cause resources such as this one or the one on CodeSampler.com to crash Torque. (These resources allow you to use more than the default eight materials that can be assigned to a terrain map.)
In terrData.h, on line 192:
This assumes a maximum of nine possible materials. While this is fine for out-of-the-box Torque, this assumption will cause an error in TerrainBlock::initMMXBlender at line 608 if you have either of the above-mentioned resources installed. (mFile will contain gibberish at that line, and the getMaterialAlphaMap method will choke.)
I traced this back to the onAdd() method, where this code executes at line 749:
Ooops! After nine loops, mMPMIndex walks off and clobbers the heap, which causes the later crash. Well, the fix is simple. Change terrData.h line 192 to read:
Problem solved!
It's not a big deal, but might be a good, fast change to prevent future hair-tearing. :)
In terrData.h, on line 192:
S32 mMPMIndex[10];
This assumes a maximum of nine possible materials. While this is fine for out-of-the-box Torque, this assumption will cause an error in TerrainBlock::initMMXBlender at line 608 if you have either of the above-mentioned resources installed. (mFile will contain gibberish at that line, and the getMaterialAlphaMap method will choke.)
I traced this back to the onAdd() method, where this code executes at line 749:
for (int i = 0; i < TerrainBlock::MaterialGroups; i++)
{
StringTableEntry fn = mMaterialFileName[i];
if (fn != NULL)
{
if(!dStrncmp(fn, "terrain.", 8))
fn += 8;
char nameBuff[512];
dStrcpy(nameBuff, mTerrFileName);
const char *p = dStrrchr(fn, '/');
if(p) p++;
else p = nameBuff;
mMPMIndex[i] = pMatMap->getIndexFromName( p );
}
else mMPMIndex[i] = -1;
}Ooops! After nine loops, mMPMIndex walks off and clobbers the heap, which causes the later crash. Well, the fix is simple. Change terrData.h line 192 to read:
S32 mMPMIndex[TerrainBlock::MaterialGroups];
Problem solved!
It's not a big deal, but might be a good, fast change to prevent future hair-tearing. :)
#3
I discovered this after merging in the latest HEAD into my source tree. Also brought some other things to light, which I will prolly be posting about in here soon.
08/18/2004 (9:22 am)
Yes, I need to learn how to submit patches for HEAD. :)I discovered this after merging in the latest HEAD into my source tree. Also brought some other things to light, which I will prolly be posting about in here soon.
#4
08/18/2004 (12:54 pm)
Cool David, looking forward to it.
#5
Best way to submit a HEAD patch is to just post a clearly written, well thought out explanation in the forums... or mail it to Tim or I.
08/18/2004 (6:52 pm)
Checked this fix in.Best way to submit a HEAD patch is to just post a clearly written, well thought out explanation in the forums... or mail it to Tim or I.
Torque Owner Stephen Clark
-s