From 63aa2ec47c2cabf1ba85dc79161bb2c383144264 Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Sun, 23 Jul 2017 20:47:31 +0100 Subject: [PATCH] Check that textures are a power of two early rather than dying in PVR code --- gl-texture.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gl-texture.c b/gl-texture.c index b22abf5..d3b4b49 100644 --- a/gl-texture.c +++ b/gl-texture.c @@ -242,6 +242,18 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat, if(internalFormat != GL_RGBA) _glKosThrowError(GL_INVALID_VALUE, "glTexImage2D"); + GLint w = width; + if(w == 0 || (w & -w) != w) { + /* Width is not a power of two. Must be!*/ + _glKosThrowError(GL_INVALID_VALUE, "glTexImage2D"); + } + + GLint h = height; + if(h == 0 || (h & -h) != h) { + /* height is not a power of two. Must be!*/ + _glKosThrowError(GL_INVALID_VALUE, "glTexImage2D"); + } + if(level < 0) _glKosThrowError(GL_INVALID_VALUE, "glTexImage2D");