aboutsummaryrefslogtreecommitdiff
path: root/gdx/jni/gdx2d/gdx2d.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdx/jni/gdx2d/gdx2d.c')
-rw-r--r--gdx/jni/gdx2d/gdx2d.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/gdx/jni/gdx2d/gdx2d.c b/gdx/jni/gdx2d/gdx2d.c
index 13ceba23b..70cfc7d98 100644
--- a/gdx/jni/gdx2d/gdx2d.c
+++ b/gdx/jni/gdx2d/gdx2d.c
@@ -17,6 +17,9 @@
#include "stb_image.h"
#include "jpgd_c.h"
+#include <android/log.h>
+#define APP_LOG "GDX"
+
static uint32_t gdx2d_blend = GDX2D_BLEND_NONE;
static uint32_t gdx2d_scale = GDX2D_SCALE_NEAREST;
@@ -358,9 +361,25 @@ static inline void clear_RGBA4444(const gdx2d_pixmap* pixmap, uint32_t col) {
}
}
-void gdx2d_clear(const gdx2d_pixmap* pixmap, uint32_t col) {
+void gdx2d_clear(const gdx2d_pixmap* pixmap, uint32_t col) {
+ if (pixmap == 0)
+ return;
+
col = to_format(pixmap->format, col);
+ // Check for malformed Pixmap
+ size_t requestedSize = pixmap->width * pixmap->height * sizeof(col);
+ size_t pixelsSize = sizeof(pixmap->pixels);
+ if (requestedSize > pixelsSize) {
+ __android_log_print(ANDROID_LOG_VERBOSE,
+ APP_LOG, "Invalid pixmap. %ix%i - Size should be %u but found %u",
+ pixmap->width,
+ pixmap->height,
+ requestedSize,
+ pixelsSize);
+ return;
+ }
+
switch(pixmap->format) {
case GDX2D_FORMAT_ALPHA:
clear_alpha(pixmap, col);