Use a more descriptive error message if love.graphics.newImage fails because the OpenGL texture can't be created.

This commit is contained in:
Alex Szpakowski
2015-10-15 14:42:57 -03:00
parent d587c206f0
commit 890802c0a3
3 changed files with 35 additions and 2 deletions
+1 -1
View File
@@ -356,7 +356,7 @@ bool Image::loadVolatile()
GLenum glerr = glGetError();
if (glerr != GL_NO_ERROR)
throw love::Exception("Cannot create image (error code 0x%x)", glerr);
throw love::Exception("Cannot create image (OpenGL error: %s)", OpenGL::errorString(glerr));
}
catch (love::Exception &)
{
+32 -1
View File
@@ -32,6 +32,7 @@
// C
#include <cstring>
#include <cstdio>
// For SDL_GL_GetProcAddress.
#include <SDL_video.h>
@@ -643,7 +644,7 @@ int OpenGL::getMaxTextureUnits() const
void OpenGL::updateTextureMemorySize(size_t oldsize, size_t newsize)
{
int64 memsize = (int64) stats.textureMemory + ((int64 )newsize - (int64) oldsize);
int64 memsize = (int64) stats.textureMemory + ((int64) newsize - (int64) oldsize);
stats.textureMemory = (size_t) std::max(memsize, (int64) 0);
}
@@ -652,6 +653,36 @@ OpenGL::Vendor OpenGL::getVendor() const
return vendor;
}
const char *OpenGL::errorString(GLenum errorcode)
{
switch (errorcode)
{
case GL_NO_ERROR:
return "no error";
case GL_INVALID_ENUM:
return "invalid enum";
case GL_INVALID_VALUE:
return "invalid value";
case GL_INVALID_OPERATION:
return "invalid operation";
case GL_OUT_OF_MEMORY:
return "out of memory";
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "invalid framebuffer operation";
case GL_CONTEXT_LOST:
return "OpenGL context has been lost";
default:
break;
}
static char text[64] = {};
memset(text, 0, sizeof(text));
sprintf(text, "0x%x", errorcode);
return text;
}
const char *OpenGL::debugSeverityString(GLenum severity)
{
switch (severity)
+2
View File
@@ -339,6 +339,8 @@ public:
**/
Vendor getVendor() const;
static const char *errorString(GLenum errorcode);
// Get human-readable strings for debug info.
static const char *debugSeverityString(GLenum severity);
static const char *debugSourceString(GLenum source);