From efa55ce6c28b66d1502c727f4d91408d57f8f82e Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Wed, 4 Sep 2013 18:11:16 +0200 Subject: [PATCH] Raise exception on invalid bitmap sizes A difference to RMXP is that negative height values will result in exceptions too. Also change Bitmap constructors to not allocate Private struct before potential exceptions. --- src/bitmap.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/bitmap.cpp b/src/bitmap.cpp index d6839da..a63909c 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -139,11 +139,14 @@ Bitmap::Bitmap(const char *filename) if (!imgSurf) throw Exception(Exception::SDLError, "SDL: %s", SDL_GetError()); - p = new BitmapPrivate; + TexFBO tex; p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888); - p->tex = gState->texPool().request(imgSurf->w, imgSurf->h); + tex = gState->texPool().request(imgSurf->w, imgSurf->h); + + p = new BitmapPrivate; + p->tex = tex; Tex::bind(p->tex.tex); Tex::uploadImage(p->tex.width, p->tex.height, imgSurf->pixels, GL_RGBA); @@ -153,9 +156,13 @@ Bitmap::Bitmap(const char *filename) Bitmap::Bitmap(int width, int height) { - p = new BitmapPrivate; + if (width <= 0 || height <= 0) + throw Exception(Exception::RGSSError, "failed to create bitmap"); - p->tex = gState->texPool().request(width, height); + TexFBO tex = gState->texPool().request(width, height); + + p = new BitmapPrivate; + p->tex = tex; clear(); }