1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

How to clear all existing surfaces?

Discussion in 'Legacy GameMaker Community Tech Support' started by lazybraingames, Feb 14, 2019 at 7:55 AM.

  1. lazybraingames

    lazybraingames Member

    Joined:
    Jul 3, 2016
    Posts:
    29
    Hi all!
    I'm trying to figure out a way for GMS to adapt to toggling from fullscreen to windowed mode while displaying surfaces. I can't seem to find a way to tell GMS to just clear all surfaces from memory (regardless of the object they're associated with or name) so that it can re-create them after the player switches from fullscreen to windowed. Is there a way to achieve this?

    Thanks for reading
     
  2. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    363
    I think you'd have to register every object that has a surface and its surfaces in a global data structure or array and then go through it
     
  3. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    991
    Surfaces are not indexed by default. You could create this index yourself, for example through a global list and adding every surface that gets created to it as well as removing every surface that is freed or happens to whoops out of existence.

    Technically, keeping this list accurate isn't required since you can check whether any surface in the list actually exists before freeing it in order to avoid crashes. You don't even have to keep a list if you're willing to loop from anywhere between 1 to your best guess at how many surfaces might have been declared up to that point, checking if they exist and wiping them if they do so, but that's merely a cop-out that relies on surfaces being indexed through incremental integers rather than being their own data type... so it's anything but best practice.
     
  4. lazybraingames

    lazybraingames Member

    Joined:
    Jul 3, 2016
    Posts:
    29
    Interesting! I was actually having issues with assigning a surface to a global variable (such as global.surf1=create_surface) so I opted to just have an object make it locally (the documentation also seems to imply this is the way to go). I suppose I could try to also create an entry in some kind of global array? Maybe it just comes down to a data structure kind of thing, but I wanted to at least make sure there wasn't a way of just telling game maker "get rid of all surfaces" before I proceeded. I'm going to try a few different ways to have a global list I can just loop through since (as best I can tell) all surfaces have to be freed when toggling fullscreen/windowed.

    Thanks for replying!
     
  5. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    298
    Wouldn't surface_free() work?
     
  6. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    991
    It makes no difference from a technical standpoint whether surfaces are under global or local scope. It would appear more natural to me to have them local, though. (This does not exclude also storing them in a global list for easier removal, though.)

    Whether you use an array, list or other data structure is up to personal preference. Either will work.
    There is no clear all button.

    If toggling full screen mode and surface freeing have any correlation at all, that would be an "is being freed" one, not a "has to be freed" one. The surfaces manual page provides additional examples. Exactly when or why surfaces go missing should not be a concern, though - there should always be a fail-safe in place.

    That works for freeing one surface. The topic's question is how to free all of them.
     
    EvanSki likes this.

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