Skip to content

Commit

Permalink
Attempt to fix NRE reported by pantheis & toadicus
Browse files Browse the repository at this point in the history
And add some comments
  • Loading branch information
sarbian committed Jul 9, 2014
1 parent e2cf63b commit 3c8e5a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions PersistentEmitterManager.cs
Expand Up @@ -58,12 +58,17 @@ public void FixedUpdate()
var persistentEmittersCopy = persistentEmitters.ToArray();
for (int i = 0; i < persistentEmittersCopy.Length; i++)
{
if (persistentEmittersCopy[i].timer > 0 && persistentEmittersCopy[i].timer < Time.fixedTime)
if (persistentEmittersCopy[i].endTime > 0 && persistentEmittersCopy[i].endTime < Time.fixedTime)
{
persistentEmittersCopy[i].EmissionStop();
}

if (persistentEmittersCopy[i].go == null || persistentEmittersCopy[i].go.transform.parent == null)
// If the gameObject is null ( when ? I forgot ... )
// or the tranform parent is null ( Emitter detached from part so the particle are not removed instantly )
// then the emitter won't be updated by the effect FixedUpdate Call. So update it here
if (persistentEmittersCopy[i].go == null
|| persistentEmittersCopy[i].go.transform == null
|| persistentEmittersCopy[i].go.transform.parent == null)
{
persistentEmittersCopy[i].EmitterOnUpdate(Vector3.zero);

Expand Down
4 changes: 2 additions & 2 deletions PersistentKSPParticleEmitter.cs
Expand Up @@ -42,7 +42,7 @@ public class PersistentKSPParticleEmitter

public bool fixedEmit = false;

public float timer = 0;
public float endTime = 0;

public double particleFraction = 0;

Expand Down Expand Up @@ -139,7 +139,7 @@ public class PersistentKSPParticleEmitter
// Detach the emitter from its parent gameobject and stop its emmission in timer seconds
public void Detach(float timer)
{
this.timer = Time.fixedTime + timer;
this.endTime = Time.fixedTime + timer;
if (this.go != null && this.go.transform.parent != null)
{
// detach from the parent so the emmitter(and its particle) don't get removed instantly
Expand Down

0 comments on commit 3c8e5a6

Please sign in to comment.