Flint Particle System Forum - removeParticle causing null reference error Sun, 27 May 2012 07:04:37 +0100 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher removeParticle causing null reference error http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1657#Comment_1657 http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1657#Comment_1657 Wed, 29 Jun 2011 10:09:24 +0100 mafsays
var rect : Rectangle = new Rectangle( 100, 300, 400, 30 );
emitter.addAction( new CollisionZone( new RectangleZone( rect.x, rect.y, rect.x + rect.width, rect.y + rect.height ) ) );
emitter.addEventListener( ParticleEvent.ZONE_COLLISION, onZoneCollision );

protected function onZoneCollision( e : ParticleEvent ) : void
{
var particle : Particle2D = Particle2D( e.particle );
emitter.removeParticle( particle );
}

this all works, but the update loop continues to try and reference the particle i've removed and i therefore get a null reference error - at what point is it safe to remove a particle to avoid this, or what's the best way to approach removing a particle based on an event dispatched during the update loop? ]]>
removeParticle causing null reference error http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1658#Comment_1658 http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1658#Comment_1658 Wed, 29 Jun 2011 10:54:18 +0100 mafsays
protected function onZoneCollision( e : ParticleEvent ) : void
{
var particle : Particle2D = Particle2D( e.particle );
particle.isDead = true;
}

this then lets the emitter take care of clearing up the particle. Still be interested to hear when, if ever, removeParticle() is a valid call to make - it doesn't seem to remove the particle as effectively as the code in update() ]]>
removeParticle causing null reference error http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1681#Comment_1681 http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1681#Comment_1681 Sun, 31 Jul 2011 16:59:15 +0100 Richard
As you point out, removeParticle doesn't work correctly during the update cycle. I've just now fixed this, and checked the fix into the github repository.

Which you should be using depends on whether you actually want to kill the particle or just remove it from the emitter and place it elsewhere. ]]>
removeParticle causing null reference error http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1686#Comment_1686 http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1686#Comment_1686 Mon, 01 Aug 2011 12:34:44 +0100 SimoensS
I want particles that have collided with a collision zone to stay where they are, so I removed them from the emitter expecting them to stay without being updated.
Is there another better way to stop certain particles from being updated, for example an ignore property ? ]]>
removeParticle causing null reference error http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1688#Comment_1688 http://flintparticles.org/forum/comments.php?DiscussionID=493&Focus=1688#Comment_1688 Sat, 06 Aug 2011 11:18:51 +0100 Richard