1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 Having problem clearing Particles/Memory Leak

Discussion in 'Programming' started by GothicLogic, Dec 3, 2019.

  1. GothicLogic

    GothicLogic Member

    Jan 16, 2018
    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 -
    FirstParticleSystem = part_system_create();
    first_particle = part_type_create();
    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);

    ///Room End Event
    part_emitter_destroy(first_emitter, first_particle); 

    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

    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
    ///This is a script
    switch (mpos)
        case 0: //Continue
        case 1: //Quit

    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.
  2. Cofefe

    Cofefe Member

    Nov 29, 2019
    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. :)
    TsukaYuriko likes this.
  3. GothicLogic

    GothicLogic Member

    Jan 16, 2018
    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
  4. NightFrost

    NightFrost Member

    Jun 24, 2016
    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.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice