
 MovableManager:RemoveParticle() crashing
So I'm trying to use RemoveParticle() (a MovableManager function) to, well, remove a particle. In particular, a projectile. For one projectile, this function works fine. For another, it makes the game crash. I'm not really sure why, since the two scripts are quite similar and have the RemoveParticle() at the end of the script where nothing else could possibly be run on it afterward.
Here's the script that works:
Code:
function Update(self)
   local targetID = SceneMan:CastMORay(self.Pos, self.Vel, self.ID, -1, true, 0);
   if targetID ~= 255 and MovableMan:GetMOFromID(targetID).GetsHitByMOs then
      local impactLocation = Vector(0,0);
      SceneMan:CastFindMORay(self.Pos, self.Vel, targetID, impactLocation, -1, true, 0);
      
      local explosion = CreateAEmitter("D7AMSR Explosion Emitter");
      explosion.Pos = impactLocation;
      explosion.RotAngle = math.atan2(self.Vel.Y, self.Vel.X) * -1;
      MovableMan:AddParticle(explosion);
      
      MovableMan:RemoveParticle(self); <--- Does not crash code
   end
end
Here's the script that doesn't work
Code:
function Create(self)
   self.referenceMass = 150;
   self.maxDamage = 500;
   self.baseHealth = 100;
end
function Update(self)
   local targetID = SceneMan:CastMORay(self.Pos, self.Vel, self.ID, -1, true, 0);
   if targetID ~= 255 and MovableMan:GetMOFromID(targetID).GetsHitByMOs then
      local targetRootID = MovableMan:GetRootMOID(targetID);
      local target = MovableMan:GetMOFromID(targetRootID);
      
      local damage = 0;
      if target.Mass ~= 0 then
         damage = (self.referenceMass/math.abs(target.Mass)) * self.baseHealth;
      else
         damage = self.maxDamage;
      end
      
      if damage > self.maxDamage then
         damage = self.maxDamage;
      end
      
      for actor in MovableMan.Actors do
         if actor.ID == target.ID then
            actor.Health = actor.Health - damage;
         end
      end
      
      MovableMan:RemoveParticle(self); <--- For some reason crashes code
   end
end
I've tired RemoveMO() as well, which has the same results. I can only imagine that in the second script, the game is somehow trying to run functions on the particle after I've removed it, but I don't know what or why.