Legacy GM Having problem clearing Particles/Memory Leak

I'm not experienced with particles really at all, I've looked all over but I cant fix my problem.
This is for a 2D Platformer.

I followed this tutorial online to help get myself familiarized with particles - https://gamedevelopment.tutsplus.co...e-gamemaker-studio-particle-system--cms-22782

i replicated the first one, the green fire effect that just sits there, here's my code -
Code:
///Creation

FirstParticleSystem = part_system_create();
first_particle = part_type_create();
part_system_depth(FirstParticleSystem,1);
part_type_shape(first_particle,pt_shape_square);
part_type_scale(first_particle,1,1);
part_type_size(first_particle,0.050,0.055,-.001,0);
part_type_color2(first_particle,8454143,65280);
part_type_alpha2(first_particle,1,0.75);
part_type_speed(first_particle,0.1,0.5,0,0);
part_type_direction(first_particle,0,359,0,0);
part_type_gravity(first_particle,0.02,90);
part_type_orientation(first_particle,0,359,10,0,true);
part_type_life(first_particle,100,150);
part_type_blend(first_particle,true);

first_emitter = part_emitter_create(FirstParticleSystem);
part_emitter_region(FirstParticleSystem, first_emitter, x-20, x+20, y-20, y+20, ps_shape_ellipse, ps_distr_gaussian);
part_emitter_stream(FirstParticleSystem,first_emitter,first_particle,2);

Code:
///Room End Event

part_type_destroy(first_particle); 
part_emitter_destroy(first_emitter, first_particle); 
part_system_destroy(FirstParticleSystem);

This is just a standalone object, I wanted to go this route because of what I am using them for with ease (and because thats just how i know how to use them) such as like this
https://imgur.com/a/6sy91OQ

----------------------------------------------------
My problem is that I cannot clear the particles when I quit the game. So if I were to force the game to move to the title screen from the pause menu, the particles will stay there thus causing a memory leak.

I can however clear the particles when I die, or when I move to the next room.

Here's my code for how I'm moving to the title screen
Code:
///This is a script
switch (mpos)
{
    case 0: //Continue
    {
        instance_destroy(obj_pausewindow);
        instance_destroy(obj_pausearrow);
        break;
    }
    case 1: //Quit
    
    {
        room_goto(roomControls);
        break;
    }

Anyone mind giving me some more knowledge on how this works? I heard about global particles, I tried my hand at that but I couldn't get it to work, is that something I'd need to go with? I'm only using it for this specific world so, does it matter?

Any help is greatly appreciated, thank you.
 
C

Cofefe

Guest
First of all, based on the code you provided, you destroy your particles in the room end event, which should be triggered when you use the room_goto command. So unless I missed something, there's no real problem with that part...

Now, if you wanted to take care of any data structures in the event the game unexpectedly closed, you could use the Game End event, however...

In GMS2 one of the new features is the Clean Up event, which is triggered whenever anything happens that removes the instance from the room it is in. It basically functions as an all-in-one Destroy, Room End and Game End event and is extremely handy for destroying particles and other volatile stuff. Using this might make your life a teensy bit easier. :)
 
I made a little more progress to find out what might be the problem at least.

I created a debug object that lets me cycle through rooms and go to the title screen [how to play], the particles clear as intended


its when i use the pause feature and go to the title screen via the script, everything in the room goes away (at least thats what it looks like to me) but the particles stay, and then i can no longer clear the particles that are stuck.



i only use gms1.4 as of right now so i dont have access to those commands gms2 uses unfortunately

im confused cause im using the same line 'room_goto()' in object and script when jumping to the title screen
 

NightFrost

Member
Comparing the gif frames on both sides of the room switch, that's clearly the same particle animation keeping running on, so for some reason quitting out of the game room is not clearing away your setup. (As opposed to you accidentally creating the particles again in title screen.) For a fix that really doesn't resolve the root issue, turn the destruct into a script and call it in your quit option handler.
 
Top