Add an exception for SDL_gpu errors.
This commit is contained in:
parent
dbf7958bdd
commit
55e6ebc954
3 changed files with 26 additions and 4 deletions
|
@ -15,6 +15,7 @@
|
|||
#include "sdl/exception.hpp"
|
||||
|
||||
#include <SDL_error.h>
|
||||
#include "gpu.hpp"
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue