Commit 9b2caeed authored by bank's avatar bank

Fix for issue #210 for ParticleData sends out-of-range data via BitStream

1. When addProtectedField used with custom setters, we need to return false, or it will set the value via regular routine after the method exists (change ParticleData::protectedSetTimes() to return false instead of true).

2. The ParticleData::sizes[] needs a custom setter, so the value is clamped in a range of 0.f and MaxParticleSize.

3. The spinRadnomMin and spinRandomMax ParticleData fields need a FRangeValidator, so it auto-clamped in a range of -1000 to 1000, as we are writing data trying to fit the values in 11 bits (as UInt upto 2048 max).
   * The description for those fields needs to be updated to use 1000 instead of 10000.
   * ParticleData::onAdd() should check for values to be in a correct range too.
parent b2e2c7b5
......@@ -149,10 +149,10 @@ void ParticleData::initPersistFields()
"Variance in lifetime of particle, from 0 - lifetimeMS." );
addField( "spinSpeed", TYPEID< F32 >(), Offset(spinSpeed, ParticleData),
"Speed at which to spin the particle." );
addField( "spinRandomMin", TYPEID< F32 >(), Offset(spinRandomMin, ParticleData),
"Minimum allowed spin speed of this particle, between -10000 and spinRandomMax." );
addField( "spinRandomMax", TYPEID< F32 >(), Offset(spinRandomMax, ParticleData),
"Maximum allowed spin speed of this particle, between spinRandomMin and 10000." );
addFieldV( "spinRandomMin", TYPEID< F32 >(), Offset(spinRandomMin, ParticleData), new FRangeValidator(-1000.f, 1000.f),
"Minimum allowed spin speed of this particle, between -1000 and spinRandomMax." );
addFieldV( "spinRandomMax", TYPEID< F32 >(), Offset(spinRandomMax, ParticleData), new FRangeValidator(-1000.f, 1000.f),
"Maximum allowed spin speed of this particle, between spinRandomMin and 1000." );
addField( "useInvAlpha", TYPEID< bool >(), Offset(useInvAlpha, ParticleData),
"@brief Controls how particles blend with the scene.\n\n"
"If true, particles blend like ParticleBlendStyle NORMAL, if false, "
......@@ -200,7 +200,8 @@ void ParticleData::initPersistFields()
"@brief Particle RGBA color keyframe values.\n\n"
"The particle color will linearly interpolate between the color/time keys "
"over the lifetime of the particle." );
addField( "sizes", TYPEID< F32 >(), Offset(sizes, ParticleData), PDC_NUM_KEYS,
addProtectedField( "sizes", TYPEID< F32 >(), Offset(sizes, ParticleData), &protectedSetSizes,
&defaultProtectedGetFn, PDC_NUM_KEYS,
"@brief Particle size keyframe values.\n\n"
"The particle size will linearly interpolate between the size/time keys "
"over the lifetime of the particle." );
......@@ -343,6 +344,22 @@ void ParticleData::unpackData(BitStream* stream)
}
}
bool ParticleData::protectedSetSizes( void *object, const char *index, const char *data)
{
ParticleData *pData = static_cast<ParticleData*>( object );
F32 val = dAtof(data);
U32 i;
if (!index)
i = 0;
else
i = dAtoui(index);
pData->sizes[i] = mClampF( val, 0.f, MaxParticleSize );
return false;
}
bool ParticleData::protectedSetTimes( void *object, const char *index, const char *data)
{
ParticleData *pData = static_cast<ParticleData*>( object );
......@@ -356,7 +373,7 @@ bool ParticleData::protectedSetTimes( void *object, const char *index, const cha
pData->times[i] = mClampF( val, 0.f, 1.f );
return true;
return false;
}
//-----------------------------------------------------------------------------
......@@ -379,11 +396,11 @@ bool ParticleData::onAdd()
Con::warnf(ConsoleLogEntry::General, "ParticleData(%s) lifetimeVariance >= lifetime", getName());
lifetimeVarianceMS = lifetimeMS - 1;
}
if (spinSpeed > 10000.0 || spinSpeed < -10000.0) {
if (spinSpeed > 1000.f || spinSpeed < -1000.f) {
Con::warnf(ConsoleLogEntry::General, "ParticleData(%s) spinSpeed invalid", getName());
return false;
}
if (spinRandomMin > 10000.0 || spinRandomMin < -10000.0) {
if (spinRandomMin > 1000.f || spinRandomMin < -1000.f) {
Con::warnf(ConsoleLogEntry::General, "ParticleData(%s) spinRandomMin invalid", getName());
spinRandomMin = -360.0;
return false;
......@@ -393,7 +410,7 @@ bool ParticleData::onAdd()
spinRandomMin = spinRandomMax - (spinRandomMin - spinRandomMax );
return false;
}
if (spinRandomMax > 10000.0 || spinRandomMax < -10000.0) {
if (spinRandomMax > 1000.f || spinRandomMax < -1000.f) {
Con::warnf(ConsoleLogEntry::General, "ParticleData(%s) spinRandomMax invalid", getName());
spinRandomMax = 360.0;
return false;
......
......@@ -79,6 +79,7 @@ class ParticleData : public SimDataBlock
StringTableEntry textureName;
GFXTexHandle textureHandle;
static bool protectedSetSizes( void *object, const char *index, const char *data );
static bool protectedSetTimes( void *object, const char *index, const char *data );
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment