From f81e20cc68dc1c232dfff72b9757a4617aec7539 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Tue, 3 Sep 2013 15:22:00 +0200 Subject: [PATCH] Raise exception on too big textures --- binding-mri/binding-util.cpp | 4 +- binding-mri/binding-util.h | 1 + binding-mri/bitmap-binding.cpp | 2 +- binding-mruby/binding-util.cpp | 65 +++++++++++++------------------- binding-mruby/binding-util.h | 1 + binding-mruby/bitmap-binding.cpp | 2 +- src/texpool.cpp | 9 ++++- 7 files changed, 41 insertions(+), 43 deletions(-) diff --git a/binding-mri/binding-util.cpp b/binding-mri/binding-util.cpp index e5dfa2c..cdd1d95 100644 --- a/binding-mri/binding-util.cpp +++ b/binding-mri/binding-util.cpp @@ -53,6 +53,7 @@ struct const char *name; } static customExc[] = { + { MKXP, "MKXPError" }, { RGSS, "RGSSError" }, { PHYSFS, "PHYSFSError" }, { SDL, "SDLError" } @@ -85,7 +86,8 @@ static const RbException excToRbExc[] = ArgumentError, PHYSFS, /* PHYSFSError */ - SDL /* SDLError */ + SDL, /* SDLError */ + MKXP /* MKXPError */ }; void raiseRbExc(const Exception &exc) diff --git a/binding-mri/binding-util.h b/binding-mri/binding-util.h index b02b017..0adcd4b 100644 --- a/binding-mri/binding-util.h +++ b/binding-mri/binding-util.h @@ -31,6 +31,7 @@ enum RbException RGSS = 0, PHYSFS, SDL, + MKXP, ErrnoENOENT, diff --git a/binding-mri/bitmap-binding.cpp b/binding-mri/bitmap-binding.cpp index 5adb7ae..b864f3b 100644 --- a/binding-mri/bitmap-binding.cpp +++ b/binding-mri/bitmap-binding.cpp @@ -48,7 +48,7 @@ RB_METHOD(bitmapInitialize) int 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); diff --git a/binding-mruby/binding-util.cpp b/binding-mruby/binding-util.cpp index 01f1ddc..f8323c2 100644 --- a/binding-mruby/binding-util.cpp +++ b/binding-mruby/binding-util.cpp @@ -66,7 +66,8 @@ static const MrbExcData excData[] = { RGSS, "RGSSError" }, { PHYSFS, "PHYSFSError" }, { SDL, "SDLError" }, - { IO, "IOError" } + { MKXP, "MKXPError" }, + { IO, "IOError" } }; static elementsN(excData); @@ -75,22 +76,22 @@ static elementsN(excData); static const MrbExcData enoExcData[] = { - ENO(E2BIG), - ENO(EACCES), - ENO(EAGAIN), - ENO(EBADF), - ENO(ECHILD), - ENO(EDEADLOCK), - ENO(EDOM), - ENO(EEXIST), - ENO(EINVAL), - ENO(EMFILE), - ENO(ENOENT), - ENO(ENOEXEC), - ENO(ENOMEM), - ENO(ENOSPC), - ENO(ERANGE), - ENO(EXDEV) + ENO(E2BIG), + ENO(EACCES), + ENO(EAGAIN), + ENO(EBADF), + ENO(ECHILD), + ENO(EDEADLOCK), + ENO(EDOM), + ENO(EEXIST), + ENO(EINVAL), + ENO(EMFILE), + ENO(ENOENT), + ENO(ENOEXEC), + ENO(ENOMEM), + ENO(ENOSPC), + ENO(ERANGE), + ENO(EXDEV) }; static elementsN(enoExcData); @@ -117,33 +118,19 @@ MrbData::MrbData(mrb_state *mrb) 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 */ static const MrbException excToMrbExc[] = { - RGSS, /* RGSSError */ - ErrnoENOENT, /* NoFileError */ - IO, + RGSS, /* RGSSError */ + ErrnoENOENT, /* NoFileError */ + IO, - TypeError, - ArgumentError, + TypeError, + ArgumentError, - PHYSFS, /* PHYSFSError */ - SDL, /* SDLError */ + PHYSFS, /* PHYSFSError */ + SDL, /* SDLError */ + MKXP /* MKXPError */ }; void raiseMrbExc(mrb_state *mrb, const Exception &exc) diff --git a/binding-mruby/binding-util.h b/binding-mruby/binding-util.h index d750794..564669a 100644 --- a/binding-mruby/binding-util.h +++ b/binding-mruby/binding-util.h @@ -64,6 +64,7 @@ enum MrbException RGSS, PHYSFS, SDL, + MKXP, ErrnoE2BIG, ErrnoEACCES, diff --git a/binding-mruby/bitmap-binding.cpp b/binding-mruby/bitmap-binding.cpp index a18bbab..b2860b2 100644 --- a/binding-mruby/bitmap-binding.cpp +++ b/binding-mruby/bitmap-binding.cpp @@ -48,7 +48,7 @@ MRB_METHOD(bitmapInitialize) mrb_int 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); diff --git a/src/texpool.cpp b/src/texpool.cpp index 65d5fa1..072a64e 100644 --- a/src/texpool.cpp +++ b/src/texpool.cpp @@ -20,6 +20,9 @@ */ #include "texpool.h" +#include "exception.h" +#include "globalstate.h" +#include "glstate.h" #include #include @@ -121,7 +124,11 @@ TexFBO TexPool::request(int width, int height) 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 */ TexFBO::init(cobj.obj);