LibGL: Support missing context in glGetError and glGetIntegerv

In its current state, ScummVM seems to invoke these methods just after
destroying the current GL context. According to the OpenGL spec:

    "Issuing GL commands when the program does not have a current
     context results in undefined behavior, up to and including program
     termination."

Our old behavior was to deref a `nullptr`, which isn't that great. For
now, protect these two methods. If other ports seem to misbehave as
well, we can always expand the check to other methods.
This commit is contained in:
Jelle Raaijmakers 2021-12-01 23:10:12 +01:00 committed by Andreas Kling
parent a06b69c5b5
commit b79642ef74
Notes: sideshowbarker 2024-07-17 22:50:29 +09:00
3 changed files with 13 additions and 0 deletions

View file

@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "GLContext.h"
#include "SoftwareGLContext.h"
#include <LibGfx/Bitmap.h>

View file

@ -14,6 +14,16 @@
namespace GL {
#define VERIFY_CURRENT_CONTEXT() \
if (!g_gl_context) { \
return; \
}
#define VERIFY_CURRENT_CONTEXT_OR_VALUE(value) \
if (!g_gl_context) { \
return value; \
}
class GLContext {
public:
virtual ~GLContext();

View file

@ -67,6 +67,7 @@ void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
GLenum glGetError()
{
VERIFY_CURRENT_CONTEXT_OR_VALUE(GL_NONE);
return g_gl_context->gl_get_error();
}
@ -117,6 +118,7 @@ void glGetFloatv(GLenum pname, GLfloat* params)
void glGetIntegerv(GLenum pname, GLint* data)
{
VERIFY_CURRENT_CONTEXT();
g_gl_context->gl_get_integerv(pname, data);
}