From c3702a1eb813c6dd1ccaa7d672db1b1bfb70c8a2 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 1 Feb 2014 03:08:59 +0400 Subject: [PATCH] Add explicit check for nullptr before destroying SDL objects This is not really needed as SDL has these checks internally, but this way it's still safer and more apparent that moved-from objects are handled properly. --- SDL2pp/Renderer.cc | 3 ++- SDL2pp/Texture.cc | 3 ++- SDL2pp/Window.cc | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/SDL2pp/Renderer.cc b/SDL2pp/Renderer.cc index c103881..16f17ab 100644 --- a/SDL2pp/Renderer.cc +++ b/SDL2pp/Renderer.cc @@ -38,7 +38,8 @@ Renderer::Renderer(Window& window, int index, Uint32 flags) { } Renderer::~Renderer() { - SDL_DestroyRenderer(renderer_); + if (renderer_ != nullptr) + SDL_DestroyRenderer(renderer_); } Renderer::Renderer(Renderer&& other) noexcept : renderer_(other.renderer_) { diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 31f2147..fa01f88 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -36,7 +36,8 @@ Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) { } Texture::~Texture() { - SDL_DestroyTexture(texture_); + if (texture_ != nullptr) + SDL_DestroyTexture(texture_); } Texture::Texture(Texture&& other) noexcept : texture_(other.texture_) { diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index 232f960..f6458ac 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -32,7 +32,8 @@ Window::Window(const char* title, int x, int y, int w, int h, Uint32 flags) { } Window::~Window() { - SDL_DestroyWindow(window_); + if (window_ != nullptr) + SDL_DestroyWindow(window_); } Window::Window(Window&& other) noexcept : window_(other.window_) {