Fix memory leak with ApplyFilter

The intention of the recent refactor was to make it so that the
temporary surfaces would be allocated only once, when the mode is
enabled, and be freed upon exit.

To do this, Graphics.cpp owns the pointers, and passes them to
ApplyFilter to modify. Except ApplyFilter doesn't actually modify the
pointers, because it's only a single pointer, not a pointer-to-pointer.
So every frame of rendering it would actually be creating a new surface
and leaking memory.

To fix this, they need to be pointer-to-pointer variables that get
modified.

I also added error logs in case the surface creation failed.
This commit is contained in:
Misa
2023-10-27 10:21:18 -07:00
parent 791310fa5d
commit ea1a014145
3 changed files with 27 additions and 20 deletions

View File

@@ -12,6 +12,6 @@ void DrawPixel(SDL_Surface* surface, int x, int y, SDL_Color color);
SDL_Color ReadPixel(const SDL_Surface* surface, int x, int y);
void UpdateFilter(void);
void ApplyFilter(SDL_Surface* src, SDL_Surface* dest);
void ApplyFilter(SDL_Surface** src, SDL_Surface** dest);
#endif /* GRAPHICSUTIL_H */