Game Development Community

Torque random crash, foliageReplicator?

by Luis Anton · in Torque Game Engine · 01/03/2005 (1:11 am) · 7 replies

Hi,

Happy new year ;)

I'm getting a random crash on windows XP with Torque 1.3. I get the classical XP 'send error log file to microsoft' window, where I press the 'debug' button. It opens VC7, and it shows fxFoliageReplicator.cpp file. It was not previously opened, so I guess the program may be crashing there.

The execution seems to stop here (SwayOffsetX = ...). I'll run without my foliage and check things, but... could there be a problem with foliage? I've been hunting this random crash bug for a few days and it's driving me mad! :)

// Is Swaying On and *not* in Sync?
if (mFieldData.mSwayOn && !mFieldData.mSwaySync)
{
// Yes, so calculate Sway Offset.
   SwayOffsetX = mFieldData.mSwayMagnitudeSide * mCosTable[(U32)pFoliageItem->SwayPhase];
   SwayOffsetY = mFieldData.mSwayMagnitudeFront * mSinTable[(U32)pFoliageItem->SwayPhase];

// Animate Sway Phase (Modulus).
   pFoliageItem->SwayPhase = pFoliageItem->SwayPhase + (pFoliageItem->SwayTimeRatio * ElapsedTime);
   if (pFoliageItem->SwayPhase >= 720.0f) pFoliageItem->SwayPhase -= 720.0f;
}

#1
01/03/2005 (9:49 pm)
Have you tried checking for null pointers? It might be its trying to access memory that it doesn't own.
#2
01/04/2005 (3:31 am)
No, I should try. Do you mean setting a debug point there with a certain condition (mFieldData or pFoliageItem = null)? Or is there a different way to do that in .net?
#3
01/11/2005 (8:43 am)
I'd check the state of the various variables (particularly this or pFoliageItem); there's a window at the bottom of the debugger (if I recall the default state correctly) which lets you do this.
#4
01/26/2005 (9:01 pm)
So I was having the same crash and hunted it down as far as I can tell, in the four if statements that handle swaying and light phasing, I changed the if statements that make sure the phase values don't go over 720:
if (mFieldData.mSwayOn && mFieldData.mSwaySync)
{
   SwayOffsetX = mFieldData.mSwayMagnitudeSide * mCosTable[(U32)mGlobalSwayPhase];
   SwayOffsetY = mFieldData.mSwayMagnitudeFront * mSinTable[(U32)mGlobalSwayPhase];

   mGlobalSwayPhase = mGlobalSwayPhase + (mGlobalSwayTimeRatio * ElapsedTime);
   // Used to be -= 720.0f
   if (mGlobalSwayPhase >= 720.0f) mGlobalSwayPhase -= ((S32)mGlobalSwayPhase / 720) * 720;
}

if (mFieldData.mLightOn && mFieldData.mLightSync)
{
   Luminance = LuminanceMidPoint + LuminanceMagnitude * mCosTable[(U32)mGlobalLightPhase];

   mGlobalLightPhase = mGlobalLightPhase + (mGlobalLightTimeRatio * ElapsedTime);
   // Used to be -= 720.0f
   if (mGlobalLightPhase >= 720.0f) mGlobalLightPhase -= ((S32)mGlobalLightPhase / 720) * 720;
}

<snip>

if (mFieldData.mSwayOn && !mFieldData.mSwaySync)
{
   SwayOffsetX = mFieldData.mSwayMagnitudeSide * mCosTable[(U32)pFoliageItem->SwayPhase];
   SwayOffsetY = mFieldData.mSwayMagnitudeFront * mSinTable[(U32)pFoliageItem->SwayPhase];

   pFoliageItem->SwayPhase = pFoliageItem->SwayPhase + (pFoliageItem->SwayTimeRatio * ElapsedTime);
   // Used to be -= 720.0f
   if (pFoliageItem->SwayPhase >= 720.0f) pFoliageItem->SwayPhase -= ((S32)pFoliageItem->SwayPhase / 720) * 720;
}

if (mFieldData.mLightOn && !mFieldData.mLightSync)
{
   Luminance = LuminanceMidPoint + LuminanceMagnitude * mCosTable[(U32)pFoliageItem->LightPhase];

   pFoliageItem->LightPhase = pFoliageItem->LightPhase + (pFoliageItem->LightTimeRatio * ElapsedTime);
   // Used to be -= 720.0f
   if (pFoliageItem->LightPhase >= 720.0f) pFoliageItem->LightPhase -= ((S32)pFoliageItem->LightPhase / 720) * 720;
}

In the original code, if ElapsedTime was really large and the value was over 1480, it'd break on the second render pass when it tried to use the new sway value (beyond the bounds of mCosTable).

Hope this helps (If anyone is looking at this post)... sorry it's hard to read...
#5
06/18/2007 (2:16 pm)
Hiya,
it took me a long time to find out why my game crash. And it is the same postion where it crash in Version 1.5. So this bug is still in the current source i guess.

I'll try your changes Andrew, or i kick all folliants from the maps if it happen again ;)
#6
06/18/2007 (3:37 pm)
Thomas, try a clean and rebuild first.

A common crash with shapeReplicator and foliageReplicator can be fixed if the source is compiled using Visual Studio 2005.
#7
06/20/2007 (6:19 am)
I did test it now by raising the multiplier for ElapsedTime in void fxFoliageReplicator::renderObject to see if the "random" crash appear. And yes this seams to be the reason why it crash - even more on slow pc.
Then i did add Andrew's change and the crash seams to be gone :)

Thanks Andrew for his post :D and i would recommend everybody who uses fxFoliageReplicator to add this ;)


edit:typos