Skip to content

Commit aa051df

Browse files
committed
Make it safe to pass nullptr through to cleanup
1 parent 0025f05 commit aa051df

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

include/cleanup.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,30 @@ void cleanup(T *t, Args&&... args){
2222
*/
2323
template<>
2424
void cleanup<SDL_Window>(SDL_Window *win){
25+
if (!win){
26+
return;
27+
}
2528
SDL_DestroyWindow(win);
2629
}
2730
template<>
2831
void cleanup<SDL_Renderer>(SDL_Renderer *ren){
32+
if (!ren){
33+
return;
34+
}
2935
SDL_DestroyRenderer(ren);
3036
}
3137
template<>
3238
void cleanup<SDL_Texture>(SDL_Texture *tex){
39+
if (!tex){
40+
return;
41+
}
3342
SDL_DestroyTexture(tex);
3443
}
3544
template<>
3645
void cleanup<SDL_Surface>(SDL_Surface *surf){
46+
if (!surf){
47+
return;
48+
}
3749
SDL_FreeSurface(surf);
3850
}
3951

0 commit comments

Comments
 (0)