Raise exception on too big textures

This commit is contained in:
Jonas Kulla 2013-09-03 15:22:00 +02:00
parent 31c007b541
commit f81e20cc68
7 changed files with 41 additions and 43 deletions

View File

@ -53,6 +53,7 @@ struct
const char *name; const char *name;
} static customExc[] = } static customExc[] =
{ {
{ MKXP, "MKXPError" },
{ RGSS, "RGSSError" }, { RGSS, "RGSSError" },
{ PHYSFS, "PHYSFSError" }, { PHYSFS, "PHYSFSError" },
{ SDL, "SDLError" } { SDL, "SDLError" }
@ -85,7 +86,8 @@ static const RbException excToRbExc[] =
ArgumentError, ArgumentError,
PHYSFS, /* PHYSFSError */ PHYSFS, /* PHYSFSError */
SDL /* SDLError */ SDL, /* SDLError */
MKXP /* MKXPError */
}; };
void raiseRbExc(const Exception &exc) void raiseRbExc(const Exception &exc)

View File

@ -31,6 +31,7 @@ enum RbException
RGSS = 0, RGSS = 0,
PHYSFS, PHYSFS,
SDL, SDL,
MKXP,
ErrnoENOENT, ErrnoENOENT,

View File

@ -48,7 +48,7 @@ RB_METHOD(bitmapInitialize)
int width, height; int width, height;
rb_get_args(argc, argv, "ii", &width, &height); rb_get_args(argc, argv, "ii", &width, &height);
b = new Bitmap(width, height); GUARD_EXC( b = new Bitmap(width, height); )
} }
setPrivateData(self, b, BitmapType); setPrivateData(self, b, BitmapType);

View File

@ -66,7 +66,8 @@ static const MrbExcData excData[] =
{ RGSS, "RGSSError" }, { RGSS, "RGSSError" },
{ PHYSFS, "PHYSFSError" }, { PHYSFS, "PHYSFSError" },
{ SDL, "SDLError" }, { SDL, "SDLError" },
{ IO, "IOError" } { MKXP, "MKXPError" },
{ IO, "IOError" }
}; };
static elementsN(excData); static elementsN(excData);
@ -75,22 +76,22 @@ static elementsN(excData);
static const MrbExcData enoExcData[] = static const MrbExcData enoExcData[] =
{ {
ENO(E2BIG), ENO(E2BIG),
ENO(EACCES), ENO(EACCES),
ENO(EAGAIN), ENO(EAGAIN),
ENO(EBADF), ENO(EBADF),
ENO(ECHILD), ENO(ECHILD),
ENO(EDEADLOCK), ENO(EDEADLOCK),
ENO(EDOM), ENO(EDOM),
ENO(EEXIST), ENO(EEXIST),
ENO(EINVAL), ENO(EINVAL),
ENO(EMFILE), ENO(EMFILE),
ENO(ENOENT), ENO(ENOENT),
ENO(ENOEXEC), ENO(ENOEXEC),
ENO(ENOMEM), ENO(ENOMEM),
ENO(ENOSPC), ENO(ENOSPC),
ENO(ERANGE), ENO(ERANGE),
ENO(EXDEV) ENO(EXDEV)
}; };
static elementsN(enoExcData); static elementsN(enoExcData);
@ -117,33 +118,19 @@ MrbData::MrbData(mrb_state *mrb)
mrb_gc_arena_restore(mrb, arena); mrb_gc_arena_restore(mrb, arena);
} }
//enum Type
//{
// RGSSError,
// NoFileError,
// IOError,
// /* Already defined by ruby */
// TypeError,
// ArgumentError,
// /* New types introduced in mkxp */
// PHYSFSError,
// SDLError
//};
/* Indexed with Exception::Type */ /* Indexed with Exception::Type */
static const MrbException excToMrbExc[] = static const MrbException excToMrbExc[] =
{ {
RGSS, /* RGSSError */ RGSS, /* RGSSError */
ErrnoENOENT, /* NoFileError */ ErrnoENOENT, /* NoFileError */
IO, IO,
TypeError, TypeError,
ArgumentError, ArgumentError,
PHYSFS, /* PHYSFSError */ PHYSFS, /* PHYSFSError */
SDL, /* SDLError */ SDL, /* SDLError */
MKXP /* MKXPError */
}; };
void raiseMrbExc(mrb_state *mrb, const Exception &exc) void raiseMrbExc(mrb_state *mrb, const Exception &exc)

View File

@ -64,6 +64,7 @@ enum MrbException
RGSS, RGSS,
PHYSFS, PHYSFS,
SDL, SDL,
MKXP,
ErrnoE2BIG, ErrnoE2BIG,
ErrnoEACCES, ErrnoEACCES,

View File

@ -48,7 +48,7 @@ MRB_METHOD(bitmapInitialize)
mrb_int width, height; mrb_int width, height;
mrb_get_args(mrb, "ii", &width, &height); mrb_get_args(mrb, "ii", &width, &height);
b = new Bitmap(width, height); GUARD_EXC( b = new Bitmap(width, height); )
} }
setPrivateData(mrb, self, b, BitmapType); setPrivateData(mrb, self, b, BitmapType);

View File

@ -20,6 +20,9 @@
*/ */
#include "texpool.h" #include "texpool.h"
#include "exception.h"
#include "globalstate.h"
#include "glstate.h"
#include <QHash> #include <QHash>
#include <QQueue> #include <QQueue>
@ -121,7 +124,11 @@ TexFBO TexPool::request(int width, int height)
return cobj.obj; return cobj.obj;
} }
// FIXME check here that requested dimensions don't exceed OpenGL limits int maxSize = glState.caps.maxTexSize;
if (width > maxSize || height > maxSize)
throw Exception(Exception::MKXPError,
"Texture dimensions [%s, %s] exceed hardware capabilities",
QByteArray::number(width), QByteArray::number(height));
/* Nope, create it instead */ /* Nope, create it instead */
TexFBO::init(cobj.obj); TexFBO::init(cobj.obj);