Skip to content

Commit 7cb3c11

Browse files
fix(particlesys): Add or simplify null-checks to createParticleSystem calls (#2724)
1 parent 5a4187c commit 7cb3c11

22 files changed

Lines changed: 188 additions & 269 deletions

File tree

Core/GameEngine/Source/GameClient/Drawable/Update/BeaconClientUpdate.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,11 @@ static ParticleSystem* createParticleSystem( Drawable *draw )
108108
templateName.format("BeaconSmokeFFFFFF");
109109
const ParticleSystemTemplate *failsafeTemplate = TheParticleSystemManager->findTemplate( templateName );
110110
DEBUG_ASSERTCRASH(failsafeTemplate, ("Doh, this is bad \n I Could not even find the white particle system to make a failsafe system out of."));
111-
if (failsafeTemplate)
111+
system = TheParticleSystemManager->createParticleSystem( failsafeTemplate );
112+
if (system)
112113
{
113-
system = TheParticleSystemManager->createParticleSystem( failsafeTemplate );
114-
if (system)
115-
{
116-
system->attachToDrawable( draw );
117-
system->tintAllColors( obj->getIndicatorColor() );
118-
}
114+
system->attachToDrawable( draw );
115+
system->tintAllColors( obj->getIndicatorColor() );
119116
}
120117
}
121118
}

Core/GameEngine/Source/GameClient/System/ParticleSys.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,9 +2061,9 @@ Bool ParticleSystem::update( Int localPlayerIndex )
20612061
if (m_attachedSystemName.isEmpty() == false)
20622062
{
20632063
const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( m_attachedSystemName );
2064-
if (tmp)
2064+
ParticleSystem *sys = TheParticleSystemManager->createParticleSystem( tmp, TRUE );
2065+
if (sys)
20652066
{
2066-
ParticleSystem *sys = TheParticleSystemManager->createParticleSystem( tmp, TRUE );
20672067
sys->setControlParticle( p );
20682068
p->controlParticleSystem( sys );
20692069
}
@@ -2867,9 +2867,7 @@ ParticleSystem *ParticleSystemTemplate::createSlaveSystem( Bool createSlaves ) c
28672867
if (m_slaveTemplate == nullptr && m_slaveSystemName.isEmpty() == false)
28682868
m_slaveTemplate = TheParticleSystemManager->findTemplate( m_slaveSystemName );
28692869

2870-
ParticleSystem *slave = nullptr;
2871-
if (m_slaveTemplate)
2872-
slave = TheParticleSystemManager->createParticleSystem( m_slaveTemplate, createSlaves );
2870+
ParticleSystem *slave = TheParticleSystemManager->createParticleSystem( m_slaveTemplate, createSlaves );
28732871

28742872
return slave;
28752873
}

Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,10 @@ void W3DTankTruckDraw::createWheelEmitters()
247247
{
248248
if (m_truckEffectIDs[i] == INVALID_PARTICLE_SYSTEM_ID)
249249
{
250-
if (const ParticleSystemTemplate *sysTemplate = TheParticleSystemManager->findTemplate(*effectNames[i]))
250+
const ParticleSystemTemplate *sysTemplate = TheParticleSystemManager->findTemplate(*effectNames[i]);
251+
ParticleSystem *particleSys = TheParticleSystemManager->createParticleSystem( sysTemplate );
252+
if (particleSys)
251253
{
252-
ParticleSystem *particleSys = TheParticleSystemManager->createParticleSystem( sysTemplate );
253254
particleSys->attachToObject(getDrawable()->getObject());
254255
// important: mark it as do-not-save, since we'll just re-create it when we reload.
255256
particleSys->setSaveable(FALSE);

Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTruckDraw.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ void W3DTruckDraw::createWheelEmitters()
170170
{
171171
if (m_truckEffectIDs[i] == INVALID_PARTICLE_SYSTEM_ID)
172172
{
173-
if (const ParticleSystemTemplate *sysTemplate = TheParticleSystemManager->findTemplate(*effectNames[i]))
173+
const ParticleSystemTemplate *sysTemplate = TheParticleSystemManager->findTemplate(*effectNames[i]);
174+
ParticleSystem *particleSys = TheParticleSystemManager->createParticleSystem( sysTemplate );
175+
if (particleSys)
174176
{
175-
ParticleSystem *particleSys = TheParticleSystemManager->createParticleSystem( sysTemplate );
176177
particleSys->attachToObject(getDrawable()->getObject());
177178
// important: mark it as do-not-save, since we'll just re-create it when we reload.
178179
particleSys->setSaveable(FALSE);

Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/AutoHealBehavior.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,10 @@ void AutoHealBehavior::pulseHealObject( Object *obj )
279279
obj->attemptHealingFromSoleBenefactor( data->m_healingAmount, getObject(), data->m_healingDelay );
280280

281281

282-
if( data->m_unitHealPulseParticleSystemTmpl )
282+
ParticleSystem *system = TheParticleSystemManager->createParticleSystem( data->m_unitHealPulseParticleSystemTmpl );
283+
if( system )
283284
{
284-
ParticleSystem *system = TheParticleSystemManager->createParticleSystem( data->m_unitHealPulseParticleSystemTmpl );
285-
if( system )
286-
{
287-
system->setPosition( obj->getPosition() );
288-
}
285+
system->setPosition( obj->getPosition() );
289286
}
290287

291288
m_soonestHealFrame = TheGameLogic->getFrame() + data->m_healingDelay;// In case onDamage tries to wake us up early

Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,9 @@ class GenericObjectCreationNugget : public ObjectCreationNugget
959959
if (!m_particleSysName.isEmpty())
960960
{
961961
const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate(m_particleSysName);
962-
if (tmp)
962+
ParticleSystem *sys = TheParticleSystemManager->createParticleSystem(tmp);
963+
if (sys)
963964
{
964-
ParticleSystem *sys = TheParticleSystemManager->createParticleSystem(tmp);
965965
sys->attachToObject(obj);
966966
}
967967
}

Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -229,40 +229,36 @@ void HelicopterSlowDeathBehavior::beginSlowDeath( const DamageInfo *damageInfo )
229229
locomotor->setMaxBraking( modData->m_maxBraking );
230230

231231
// attach particle system to bone if present
232-
if( modData->m_attachParticleSystem )
232+
ParticleSystem *pSys = TheParticleSystemManager->createParticleSystem( modData->m_attachParticleSystem );
233+
if( pSys )
233234
{
234-
ParticleSystem *pSys = TheParticleSystemManager->createParticleSystem( modData->m_attachParticleSystem );
235-
if( pSys )
235+
236+
// where do the offset attachment to
237+
if( modData->m_attachParticleBone.isEmpty() == FALSE )
236238
{
239+
Drawable *draw = getObject()->getDrawable();
237240

238-
// where do the offset attachment to
239-
if( modData->m_attachParticleBone.isEmpty() == FALSE )
241+
if( draw )
240242
{
241-
Drawable *draw = getObject()->getDrawable();
243+
Coord3D pos;
242244

243-
if( draw )
244-
{
245-
Coord3D pos;
246-
247-
if( draw->getPristineBonePositions( modData->m_attachParticleBone.str(), 0, &pos, nullptr, 1 ) )
248-
pSys->setPosition( &pos );
249-
250-
}
245+
if( draw->getPristineBonePositions( modData->m_attachParticleBone.str(), 0, &pos, nullptr, 1 ) )
246+
pSys->setPosition( &pos );
251247

252248
}
253-
else
254-
{
255249

256-
// use location coord specified ... it will be zero if not given which is center of obj anyway
257-
pSys->setPosition( &modData->m_attachParticleLoc );
258-
259-
}
250+
}
251+
else
252+
{
260253

261-
// attach the particle system to the object
262-
pSys->attachToObject( getObject() );
254+
// use location coord specified ... it will be zero if not given which is center of obj anyway
255+
pSys->setPosition( &modData->m_attachParticleLoc );
263256

264257
}
265258

259+
// attach the particle system to the object
260+
pSys->attachToObject( getObject() );
261+
266262
}
267263

268264

Generals/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,27 +258,21 @@ void LaserUpdate::initLaser( const Object *parent, const Coord3D *startPos, cons
258258
if( data->m_particleSystemName.isNotEmpty() )
259259
{
260260
const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( data->m_particleSystemName );
261-
if( tmp )
261+
system = TheParticleSystemManager->createParticleSystem( tmp );
262+
if( system )
262263
{
263-
system = TheParticleSystemManager->createParticleSystem( tmp );
264-
if( system )
265-
{
266-
m_particleSystemID = system->getSystemID();
267-
}
264+
m_particleSystemID = system->getSystemID();
268265
}
269266
}
270267

271268
//If we don't have a particle system for the target effect, create it.
272269
if( data->m_targetParticleSystemName.isNotEmpty() )
273270
{
274271
const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( data->m_targetParticleSystemName );
275-
if( tmp )
272+
system = TheParticleSystemManager->createParticleSystem( tmp );
273+
if( system )
276274
{
277-
system = TheParticleSystemManager->createParticleSystem( tmp );
278-
if( system )
279-
{
280-
m_targetParticleSystemID = system->getSystemID();
281-
}
275+
m_targetParticleSystemID = system->getSystemID();
282276
}
283277
}
284278
}

Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -849,15 +849,11 @@ void ParticleUplinkCannonUpdate::createConnectorFlare( IntensityTypes intensity
849849
if( str.isNotEmpty() )
850850
{
851851
const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( str );
852-
ParticleSystem *system;
853-
if( tmp )
852+
ParticleSystem *system = TheParticleSystemManager->createParticleSystem( tmp );
853+
if( system )
854854
{
855-
system = TheParticleSystemManager->createParticleSystem( tmp );
856-
if( system )
857-
{
858-
m_connectorSystemID = system->getSystemID();
859-
system->setPosition( &m_connectorNodePosition );
860-
}
855+
m_connectorSystemID = system->getSystemID();
856+
system->setPosition( &m_connectorNodePosition );
861857
}
862858
}
863859
}
@@ -885,14 +881,11 @@ void ParticleUplinkCannonUpdate::createLaserBaseFlare( IntensityTypes intensity
885881
if( str.isNotEmpty() )
886882
{
887883
const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( str );
888-
if( tmp )
884+
ParticleSystem *system = TheParticleSystemManager->createParticleSystem( tmp );
885+
if( system )
889886
{
890-
ParticleSystem *system = TheParticleSystemManager->createParticleSystem( tmp );
891-
if( system )
892-
{
893-
m_laserBaseSystemID = system->getSystemID();
894-
system->setPosition( &m_laserOriginPosition );
895-
}
887+
m_laserBaseSystemID = system->getSystemID();
888+
system->setPosition( &m_laserOriginPosition );
896889
}
897890
}
898891
}

Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -616,30 +616,27 @@ void SlavedUpdate::setRepairState( RepairStates repairState )
616616
if( !data->m_weldingSysName.isEmpty() )
617617
{
618618
const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( data->m_weldingSysName );
619-
if( tmp )
619+
ParticleSystem *weldingSys = TheParticleSystemManager->createParticleSystem(tmp);
620+
if( weldingSys )
620621
{
621-
ParticleSystem *weldingSys = TheParticleSystemManager->createParticleSystem(tmp);
622-
if( weldingSys )
622+
Coord3D pos;
623+
//Get the bone position
624+
if( draw->getPristineBonePositions( data->m_weldingFXBone.str(), 0, &pos, nullptr, 1 ) )
623625
{
624-
Coord3D pos;
625-
//Get the bone position
626-
if( draw->getPristineBonePositions( data->m_weldingFXBone.str(), 0, &pos, nullptr, 1 ) )
627-
{
628-
pos.add( obj->getPosition() );
629-
}
630-
else
631-
{
632-
pos.set( obj->getPosition() );
633-
}
634-
635-
weldingSys->setPosition( &pos );
636-
Real time = (Real)(m_framesToWait * LOGICFRAMES_PER_SECOND);
637-
weldingSys->setLifetimeRange( time, time );
638-
639-
AudioEventRTS soundToPlay = TheAudio->getMiscAudio()->m_repairSparks;
640-
soundToPlay.setPosition( &pos );
641-
TheAudio->addAudioEvent( &soundToPlay );
626+
pos.add( obj->getPosition() );
642627
}
628+
else
629+
{
630+
pos.set( obj->getPosition() );
631+
}
632+
633+
weldingSys->setPosition( &pos );
634+
Real time = (Real)(m_framesToWait * LOGICFRAMES_PER_SECOND);
635+
weldingSys->setLifetimeRange( time, time );
636+
637+
AudioEventRTS soundToPlay = TheAudio->getMiscAudio()->m_repairSparks;
638+
soundToPlay.setPosition( &pos );
639+
TheAudio->addAudioEvent( &soundToPlay );
643640
}
644641
}
645642

0 commit comments

Comments
 (0)