A crash when using particle effects

I’m currently working on getting particle systems working in my project, and have hit a bit of a snag.

Eternal emitters, that never die, seem to work well enough. Unfortunately, setting the system to grow older in the hopes of producing a system of limited lifetime - and, perhaps even more valuably to me, a burst emitter - seems to result in a crash once the emitter’s time runs out.

This seems to be the case whether it’s done in the Particle Panel or in my own budding game, by manually editing the file so that the relevant lines to read “setSystemLifespan(<some number, perhaps zero>)” and “setSystemGrowsOlderFlag(1)”.

[edit]

Oh, and I’m using Panda 1.5.2.

[/edit]

I’m not sure of what other parameters might be relevant, so I won’t attempt to post any unless asked for them.

What suggestions have you?

On a similar note, the particle panel always crashed on me when I checked the grow older checkbox before setting a lifespan, i.e., lifespan = 0.

I find that the panel crashes whichever I do first, the difference being that if I set a lifetime first the program sometimes lasts a little time before crashing.

My guess is that the life-timer is running in the background, and the time to crash is simply varying as a result of setting the “System Grows Older” flag at varying points during the lifetime.

In your case, BrianInSuwon, I would imagine that, presuming the problem to be manifesting in the same way on your end, the particle panel is dying immediately simply because the particle system’s life ends immediately.

i had a simple patch that fixed 90% of the crashes for me some place on the forum.

I actually came upon that during my recent searches, as I recall. It’s this one, not so?

If that is the correct one, then am I not correct in thinking that that’s only a patch for the Particle Panel? My problem, as I mentioned, occurs in the game itself as well, it seems, and not only in the panel…

ok yeah i the problem with the panel is they way it handles integers. You can accedentally get really large values which locks up the computer. I did a fix to not cause large values. Thats basically it. I run into problems with it too… but i think they where on my end: trying to do too much.

If you get a sure method of reproducing the problem we can try to fix it.

Well, it seems to happen pretty consistently on my end. :confused:

Whenever I set a particle system to grow older, the resulting system seems to crash the program.

Strangely, it seems now that it doesn’t wait for the lifetime of the system to be over, apparently crashing on system creation, but still only if the system is set to grow older. o_0

Here are what I believe to be the relevant excerpts from the code that I used to test this tonight:

Amongst my includes:

from direct.particles.Particles import Particles
from direct.particles.ParticleEffect import ParticleEffect

~

In World::__init__ :

        base.enableParticles()

~

World::dealWithShotImpact :
(Handles the effects of a WeaponsFire object hitting something that apply to all current cases.  The below is the entire method)

        effect = ParticleEffect()
        effect.loadConfig(Filename("steam.ptf"))
        effect.start(render)
        effect.setPos(pos)
        shot.kill()

~
In the copy of "steam.ptf" that I have in my project folder:

p0.setSystemLifespan(10.0000)
...
p0.setSystemGrowsOlderFlag(1)

I took a look through the source code, and, while I’m by no means certain, I am suspicious of two particular lines in “particleSystemManager.cxx”, which occur in the following code, in the method “do_particles(float dt)”. I’ve marked the lines in question with double closing angled brackets (">>").

cur = _ps_list.begin();

  //  cout << "PSM::do_particles on a vector of size " << _ps_list.size() << endl;
  //  int cs = 0;

  while (cur != _ps_list.end()) {
    ParticleSystem *cur_ps = *cur;

    // update this system
    if (cur_ps->get_active_system_flag() == true) {
      //      cout << "  system " << cs++ << endl;
      //      cout << "  count is: " << cur_ps->get_render_parent()->get_ref_count() << endl;
      cur_ps->update(dt);

      // Handle age:
      if (cur_ps->get_system_grows_older_flag() == true) {
        float age = cur_ps->get_system_age() + dt;
        cur_ps->set_system_age(age);

        // handle death
        if (age >= cur_ps->get_system_lifespan()) {
          plist< PT(ParticleSystem) >::iterator kill = cur;
>>        ++cur;

          _ps_list.erase(kill);
          render_due = false;
        }
      }

      // handle render
      if (render_due) {
        cur_ps->render();
      }
    }

>>  ++cur;
  }

Note that, if I read that correctly and am not much mistaken, when a particle system dies “cur” ends up being incremented twice, and could thus overrun _ps_list.end(), potentially resulting in a crash when the iterator is next used.

Note, however, that this is in 1.5.2; I don’t know whether this has been changed in 1.5.3, or whether this bug exists in that version at all.

Sorry to necro, but I wanted to ask if anyone else has been seeing this?

It seems the crash behavior is still there in Panda 1.6.2 under Windows. If I set the setSystemGrowsOlderFlag flag to true, my particles instantly crash.