Skip to content

Commit

Permalink
Add an exception for SDL_gpu errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Aug 11, 2014
1 parent dbf7958 commit 55e6ebc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/sdl/exception.cpp
Expand Up @@ -15,6 +15,7 @@
#include "sdl/exception.hpp"

#include <SDL_error.h>
#include "gpu.hpp"

namespace sdl
{
Expand All @@ -29,9 +30,25 @@ static std::string create_error(const std::string& operation,
}
}

static std::string create_gpu_error(const std::string &op,
const bool fetch_error_msg)
{
if (fetch_error_msg) {
return op + " Error »" + GPU_PopErrorCode().details + "«.\n";
} else {
return op;
}
}

texception::texception(const std::string& operation, const bool use_sdl_error)
: game::error(create_error(operation, use_sdl_error))
{
}

tgpu_exception::tgpu_exception(const std::string &op,
const bool fetch_error_msg)
: game::error(create_gpu_error(op, fetch_error_msg))
{
}

} // namespace sdl
5 changes: 5 additions & 0 deletions src/sdl/exception.hpp
Expand Up @@ -39,6 +39,11 @@ struct texception : public game::error
texception(const std::string& operation, const bool use_sdl_error);
};

struct tgpu_exception : public game::error
{
tgpu_exception(const std::string &op, const bool fetch_error_msg);
};

} // namespace sdl

#endif
8 changes: 4 additions & 4 deletions src/sdl/image.cpp
Expand Up @@ -43,7 +43,7 @@ timage::timage(Uint16 w, Uint16 h)
clip_ = create_gpu_rect(0, 0, w, h);
image_ = GPU_CreateImage(w, h, GPU_FORMAT_RGBA);
if (image_ == NULL) {
//TODO: report errorr
throw tgpu_exception("Failed to construct timage object.", true);
} else {
image_->refcount = 1;
static SDL_Color black = {0, 0, 0, 0};
Expand All @@ -65,7 +65,7 @@ timage::timage(const std::string &file)
, vwrap_(GPU_WRAP_NONE)
{
if (image_ == NULL) {
//TODO: report error
throw tgpu_exception("Failed to construct timage object.", true);
} else {
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
image_->refcount = 1;
Expand All @@ -89,7 +89,7 @@ timage::timage(const surface &source)
, smooth_(false)
{
if (image_ == NULL) {
//TODO: report error
throw tgpu_exception("Failed to construct timage object.", true);
} else {
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
image_->refcount = 1;
Expand All @@ -113,7 +113,7 @@ timage::timage(SDL_Surface *source)
, smooth_(false)
{
if (image_ == NULL) {
//TODO: report error
throw tgpu_exception("Failed to construct timage object.", true);
} else {
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
image_->refcount = 1;
Expand Down

0 comments on commit 55e6ebc

Please sign in to comment.