• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Particle system needed every step

J

jana

Guest
I'm having serious crashing issues with my game, when I press the escape key or the quit button:
Code:
// destroy particle systems and do other cleanup

game_end();
and when I click my game restart button
Code:
// remove particle systems and do other cleanup

(room_goto(rm_menu))
There were no crashing issues until I added the particle systems. It doesn't crash if I play the game for a minute then press the escape key. It always crashes if I play for 10 minutes then press the escape key. It'll crash if I play for a shorter period of time, but use a lot of the particle systems. Sometimes it crashes when a keystroke creates a particle system. So, I'm thinking I'm not properly destroying the partcle systems.

Most of the effects are bursts, but there are two that follow the object for a while, and these two effects crash the game the fastest.

With one of them, when my object is in a certain state, called blocked, an effect appears on top of it and stays until it gets unblocked. Video below. The red triangle will get a red cloud around it:
http://www.screencast.com/t/dV7xRvL9QXlc

The state variable "blocked" is set using a keystroke, then the object watches for it in the step event and adds the cloud if blocked is true:
Code:
if(blocked)
{
if(part_type_exists(particleVibratingRedCircle)) {part_type_destroy(particleVibratingRedCircle);}
if(part_system_exists(par_vibratingRedCircle)) {part_system_destroy(par_vibratingRedCircle);}

par_vibratingRedCircle = part_system_create();

particleVibratingRedCircle = part_type_create();
part_type_shape(particleVibratingRedCircle,pt_shape_ring);
part_type_size(particleVibratingRedCircle,0.10,0.49,-0.29,0);
part_type_scale(particleVibratingRedCircle,3.00,3.65);
part_type_color3(particleVibratingRedCircle,255,255,255);
part_type_alpha3(particleVibratingRedCircle,0.94,0.47,0.00);
part_type_speed(particleVibratingRedCircle,4.59,8.34,0.32,0);
part_type_direction(particleVibratingRedCircle,0,359,0,6);
part_type_orientation(particleVibratingRedCircle,49,236,0.40,3,1);
part_type_blend(particleVibratingRedCircle,0);
part_type_life(particleVibratingRedCircle,36,41);

part_particles_create(par_vibratingRedCircle,x,y,particleVibratingRedCircle,15);

}
Then I destroy the system for the last time when the object is unblocked, which could happen in two places in the code, when a certain condition is met, and I use this same code in both places:
Code:
if(obj_conductor.challengerIsBlockedCount < 1)
{
        blocked = 0;
        if(instance_exists(par_vibratingRedCircle))
        {
             part_system_destroy(par_vibratingRedCircle);
        } 
}
I wasn't sure how to do this to make sure that the effect would be there for the whole time the object is blocked. So I'm recreating the system each step, after destroying the one for the previous step. Could this be the source of my crashing issue? After I added the two lines that destroy the previous system
Code:
if(part_type_exists(particleVibratingRedCircle)) {part_type_destroy(particleVibratingRedCircle);}
if(part_system_exists(par_vibratingRedCircle)) {part_system_destroy(par_vibratingRedCircle);}
the number of crashes went way down. But maybe there's another way to do this?

Also, as I indicated at the beginning of my post, I'm checking on game end and when I go to a new room for particle systems that somehow didn't get destroyed, and destroying them, using code similar to the two lines above, for each particle system in the game. Maybe it's overkill - crashing the game?

Any comments/suggestions gratefully appreciated.
 
Last edited by a moderator:

Kyon

Member
Try
Code:
part_system_clear(par_vibratingRedCircle);
Also I don't think instance_exists(par_vibratingRedCircle) works.
Unless you have a object that has the same name as your particle system, then that's the problem probably.

Also don't detroy the part type. I don't think that's needed.
 
J

jana

Guest
Just to make sure I understand, are you saying replace the two lines
Code:
if(part_type_exists(particleVibratingRedCircle)) {part_type_destroy(particleVibratingRedCircle);}
if(part_system_exists(par_vibratingRedCircle)) {part_system_destroy(par_vibratingRedCircle);}
with
Code:
part_system_clear(par_vibratingRedCircle);
?
 

Kyon

Member
Just to make sure I understand, are you saying replace the two lines
Code:
if(part_type_exists(particleVibratingRedCircle)) {part_type_destroy(particleVibratingRedCircle);}
if(part_system_exists(par_vibratingRedCircle)) {part_system_destroy(par_vibratingRedCircle);}
with
Code:
part_system_clear(par_vibratingRedCircle);
?
Yes.
 
J

jana

Guest
This revised code is working. Thanks for pointing me in the right direction.
Code:
if(blocked)
{

if(part_system_exists(par_vibratingRedCircle)) {part_system_clear(par_vibratingRedCircle);}
if(!part_system_exists(par_vibratingRedCircle)) {par_vibratingRedCircle = part_system_create();}
if(!part_type_exists(particleVibratingRedCircle))
{
    particleVibratingRedCircle = part_type_create();
    part_type_shape(particleVibratingRedCircle,pt_shape_ring);
    part_type_size(particleVibratingRedCircle,0.10,0.49,-0.29,0);
    part_type_scale(particleVibratingRedCircle,3.00,3.65);
    part_type_color3(particleVibratingRedCircle,255,255,255);
    part_type_alpha3(particleVibratingRedCircle,0.94,0.47,0.00);
    part_type_speed(particleVibratingRedCircle,4.59,8.34,0.32,0);
    part_type_direction(particleVibratingRedCircle,0,359,0,6);
    part_type_orientation(particleVibratingRedCircle,49,236,0.40,3,1);
    part_type_blend(particleVibratingRedCircle,0);
    part_type_life(particleVibratingRedCircle,36,41);
}
part_particles_create(par_vibratingRedCircle,x,y,particleVibratingRedCircle,15);
Then to destroy:
Code:
if(part_type_exists(particleVibratingRedCircle)) {part_type_destroy(particleVibratingRedCircle)}
if(part_system_exists(par_vibratingRedCircle)) {part_system_destroy(par_vibratingRedCircle);}
 
J

jana

Guest
Oops, I need to go back and remove this line, because it's not needed:
Code:
if(part_type_exists(particleVibratingRedCircle)) {part_type_destroy(particleVibratingRedCircle)}
 
Top