In SDL, does SDL_Quit () free every surface?

Basically, on surfaces that will exist until the program completes, do I need to run SDL_FreeSurface()for each of them, or SDL_Quit()will it take care of all this for me?

I ask mainly because pointers to some of my surfaces are members of the class, so I will need to track every instance of the class (in a global array or something else) if I want to run SDL_FreeSurface()on each of their respective surfaces. If SDL_Quit () does it all in one fell swoop for me, I'd rather go with this: D

+3
source share
3 answers

It has been a while since I used SDL, but I’m sure that SDL_Quit simply cleans the surface of the screen (the main screen buffer that you configured at the beginning). You must clear other manually created surfaces or get leaks. Of course, since they are already members of the class, one way to do this would be to simply free them in the class destructor.

+2
source

I checked the SDL 1.2.15 source code to see what actually happens when called SDL_Quit. Gemini14's answer is correct: SDL_Quitonly the main SDL_Surface returned will be freed SDL_SetVideoMode.

That's why:

  • SDLQuitcalls SDLQuitSubSystemto exit each subsystem
  • SDLQuitSubSystem will call several functions to exit the subsystem
    • , SDL_VideoQuit.
  • SDL_VideoQuit , current_video NULL.
    • current_video NULL, .
    • SDL_FreeSurface SDL_ShadowSurface SDL_VideoSurface
      • SDL_ShadowSurface SDL_VideoSurface SDL_SetVideoMode

SDL_FreeSurface SDL_Surface, SDL_SetVideoMode, , SDL_Surface SDL_Quit SDL_FreeSurface.

, , SDL_Surface , SDL_Quit.

+3

, , , SDL_FreeSurface().

, , malloc , , , .

int **memspots[1024];
for (i = 0; i < 1024; i++) {
  memspots[i] = malloc(1 * sizeof(int *)); // 1024 pointers to ints stored in heap memory
}

, , .

for (i = 0; i < 1024; i++) {
  free(memspots[i]);
}

, , , , , .

My GL SDL SDL_Surface ( SDL_image) :

  if (surface != NULL) // Will be NULL if everything failed and SOMEHOW managed to get here
    SDL_FreeSurface();

  return;
+1
source

Source: https://habr.com/ru/post/1751325/


All Articles