From 8ea1edbc2a6d3eb56db35151d15c62abdb580f9f Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 17 Jul 2016 17:44:38 -0300 Subject: [PATCH] Cause a Lua error instead of silently failing if a vertex buffer memory allocation fails. --- src/modules/graphics/opengl/GLBuffer.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/opengl/GLBuffer.cpp b/src/modules/graphics/opengl/GLBuffer.cpp index 6658e8fdd..4cee2f34a 100644 --- a/src/modules/graphics/opengl/GLBuffer.cpp +++ b/src/modules/graphics/opengl/GLBuffer.cpp @@ -58,12 +58,10 @@ GLBuffer::GLBuffer(size_t size, const void *data, GLenum target, GLenum usage, u if (data != nullptr) memcpy(memory_map, data, size); - bool ok = load(data != nullptr); - - if (!ok) + if (!load(data != nullptr)) { delete[] memory_map; - throw love::Exception("Could not load VBO."); + throw love::Exception("Could not load vertex buffer (out of VRAM?)"); } } @@ -221,13 +219,16 @@ bool GLBuffer::load(bool restore) GLBuffer::Bind bind(*this); + while (glGetError() != GL_NO_ERROR) + /* Clear the error buffer. */; + // Copy the old buffer only if 'restore' was requested. const GLvoid *src = restore ? memory_map : nullptr; // Note that if 'src' is '0', no data will be copied. glBufferData(getTarget(), (GLsizeiptr) getSize(), src, getUsage()); - return true; + return (glGetError() == GL_NO_ERROR); } void GLBuffer::unload()