From 890802c0a3d1a6a2049cbf6564a94078990dd379 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 15 Oct 2015 14:42:57 -0300 Subject: [PATCH] Use a more descriptive error message if love.graphics.newImage fails because the OpenGL texture can't be created. --- src/modules/graphics/opengl/Image.cpp | 2 +- src/modules/graphics/opengl/OpenGL.cpp | 33 +++++++++++++++++++++++++- src/modules/graphics/opengl/OpenGL.h | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index 9503d12e6..f86ce5b49 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -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 &) { diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index df1092a0c..dcf7c9727 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -32,6 +32,7 @@ // C #include +#include // For SDL_GL_GetProcAddress. #include @@ -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) diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index 414245319..d4ec16deb 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -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);