Game Development Community

Reply to Torque X 3.0.0.0 Release Notes -

by Christian Rousselle · in Torque X 2D · 05/10/2009 (7:28 am) · 4 replies

- A scene that contains a particle effect with "particle life variance" >= 4 will crash on load on Xbox360.

I am not sure that is crashes but it will trigger an Assert. This also happens for the PC version. The function _CheckLifeTime() in T2DParticleEmitter.cs is responsible.

Assert.Fatal(minLifeTime - 0.5f * maxLifeScale * maxLifeVar > 0.0f, "Particle effect life time can be zero or negative");

/*
   where minFileTime = _emitterData.ParticleLifeBase.DefaultValue; -> 
   this is always 2 and therefore maxLifeScale * maxLifeVar must not be
   greater than 4
*/

However I am not sure why this is implemented like that.

#1
07/16/2009 (9:36 pm)
Ran into this problem tonight as well. We don't have the source code though, so we can't fix it.
#2
07/17/2009 (8:49 am)
This comment makes it pretty clear that the valid range must be < 4. Why is there an assert? Just clamp the darn thing down.
#3
07/17/2009 (9:05 am)
I added the comment - it is not in the original source. Still I do not understand why this was done this way.
#4
07/17/2009 (9:44 am)
Looking at the code a few lines above it:
float minLifeTime = lifeBase.DefaultValue;
for (int i = 0; i < lifeBase.Count; i++)
    minLifeTime = Math.Min(minLifeTime, lifeBase.GetKeyValue(i));
you can see the the minFileTime isn't always going to be the default (2.0) but can be less if there is at least one key with a lower value. However, it is prevented from ever being greater than that default, which is the problem.

With the formula checked in the Assert, it basically is saying that the maxLifeVar (maximum value of all keys set for that; no lower than default of 0.0) must be no greater than double the minimum life base. So, the variance is the total range of variance, meaning a variance of 4 can be up to 2 greater than the base, or down to 2 less than the base.

For a fix, it seems to me that the default should only apply when there are no keys set for life base. After all, that's what default means. But when there is at least one key, min should only be the minimum of those keys and not take into account the default.

So for those of you fortunate enough to have the source, something like this should work (replace the code I quoted above with this):
float minLifeTime;
if (lifeBase.Count == 0)
    minLifeTime = lifeBase.DefaultValue;
else
{
    minLifeTime = lifeBase.GetKeyValue(0);
    for (int i = 1; i < lifeBase.Count; i++)
        minLifeTime = Math.Min(minLifeTime, lifeBase.GetKeyValue(i));
}
I haven't actually tested this out, so if you try it, let us know if it works and it can be submitted as a bug fix. Also, it probably doesn't make sense for life base (minLifeTime) to be <= 0, so that could be checked for as well right after line #8, but since the original code allowed for that, I didn't bother.