From ad1e6879dfef2a9a77c2d6af4c8a2677b04df62c Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Sat, 27 Dec 2014 05:17:01 +0300 Subject: [PATCH] Check for errors after calling SDL_image functions Fixes #20 --- SDL2pp/Texture.cc | 6 ++++-- SDL2pp/Texture.hh | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 9b6ceec..0750ca3 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -46,11 +46,13 @@ Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) { #ifdef SDL2PP_WITH_IMAGE Texture::Texture(Renderer& renderer, RWops& rwops) { - texture_ = IMG_LoadTexture_RW(renderer.Get(), rwops.Get(), 0); + if ((texture_ = IMG_LoadTexture_RW(renderer.Get(), rwops.Get(), 0)) == nullptr) + throw Exception("IMG_LoadTexture_RW failed"); } Texture::Texture(Renderer& renderer, const std::string& path) { - texture_ = IMG_LoadTexture(renderer.Get(), path.c_str()); + if ((texture_ = IMG_LoadTexture(renderer.Get(), path.c_str())) == nullptr) + throw Exception("IMG_LoadTexture failed"); } #endif diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index b4e72f9..17ff1dd 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -194,6 +194,8 @@ public: /// \param renderer Rendering context to create texture for /// \param rwops RWops used to access an image file /// + /// \throws SDL2pp::Exception + /// //////////////////////////////////////////////////////////// Texture(Renderer& renderer, RWops& rwops); @@ -203,6 +205,8 @@ public: /// \param renderer Rendering context to create texture for /// \param filename Path to an image file /// + /// \throws SDL2pp::Exception + /// //////////////////////////////////////////////////////////// Texture(Renderer& renderer, const std::string& filename); #endif