Check for errors after calling SDL_image functions

Fixes #20
This commit is contained in:
Dmitry Marakasov 2014-12-27 05:17:01 +03:00
parent 69d93bc6e4
commit ad1e6879df
2 changed files with 8 additions and 2 deletions

View File

@ -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

View File

@ -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