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.
This commit is contained in:
Dmitry Marakasov 2014-02-01 03:08:59 +04:00
parent 411c62a3cc
commit c3702a1eb8
3 changed files with 6 additions and 3 deletions

View File

@ -38,7 +38,8 @@ Renderer::Renderer(Window& window, int index, Uint32 flags) {
} }
Renderer::~Renderer() { Renderer::~Renderer() {
SDL_DestroyRenderer(renderer_); if (renderer_ != nullptr)
SDL_DestroyRenderer(renderer_);
} }
Renderer::Renderer(Renderer&& other) noexcept : renderer_(other.renderer_) { Renderer::Renderer(Renderer&& other) noexcept : renderer_(other.renderer_) {

View File

@ -36,7 +36,8 @@ Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) {
} }
Texture::~Texture() { Texture::~Texture() {
SDL_DestroyTexture(texture_); if (texture_ != nullptr)
SDL_DestroyTexture(texture_);
} }
Texture::Texture(Texture&& other) noexcept : texture_(other.texture_) { Texture::Texture(Texture&& other) noexcept : texture_(other.texture_) {

View File

@ -32,7 +32,8 @@ Window::Window(const char* title, int x, int y, int w, int h, Uint32 flags) {
} }
Window::~Window() { Window::~Window() {
SDL_DestroyWindow(window_); if (window_ != nullptr)
SDL_DestroyWindow(window_);
} }
Window::Window(Window&& other) noexcept : window_(other.window_) { Window::Window(Window&& other) noexcept : window_(other.window_) {