aboutsummaryrefslogtreecommitdiff
path: root/src/OpenGLSupport.cpp
diff options
context:
space:
mode:
authorJesse Talavera-Greenberg <jesse@jesse.tg>2023-09-15 09:31:05 -0400
committerGitHub <noreply@github.com>2023-09-15 15:31:05 +0200
commitdb963aa002cdf943c86d19f8abd3f4fd40be38ec (patch)
treebded72c0147f3749d3f346266ed4b1321e3b2979 /src/OpenGLSupport.cpp
parent1aaf22d181e55abb8ad27be89ebae106b1c1cfcf (diff)
Make the NDS teardown more robust (#1798)
* Make cleanup a little more robust to mitigate undefined behavior - Add some null checks before cleaning up the GPU3D renderer - Make sure that all deleted objects are null - Move cleanup logic out of an assert call - Note that deleting a null pointer is a no-op, so there's no need to check for null beforehand - Use RAII for GLCompositor instead of Init/DeInit methods * Replace a DeInit call that I missed * Make ARMJIT_Memory less likely to generate errors - Set FastMem7/9Start to nullptr at the end - Only close and unmap the file if it's initialized * Make Renderer3D manage its resources with RAII * Don't try to deallocate frontend resources that aren't loaded * Make ARMJIT_Memory::DeInit more robust on the Switch * Reset MemoryFile on Windows to INVALID_HANDLE_VALUE, not nullptr - There is a difference * Don't explicitly store a Valid state in GLCompositor or the 3D renderers - Instead, create them with static methods while making the actual constructors private * Make initialization of OpenGL resources fail if OpenGL isn't loaded * assert that OpenGL is loaded instead of returning failure
Diffstat (limited to 'src/OpenGLSupport.cpp')
-rw-r--r--src/OpenGLSupport.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/OpenGLSupport.cpp b/src/OpenGLSupport.cpp
index 958930d..f1914fc 100644
--- a/src/OpenGLSupport.cpp
+++ b/src/OpenGLSupport.cpp
@@ -29,6 +29,12 @@ bool BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, const char*
int len;
int res;
+ if (!glCreateShader)
+ {
+ Log(LogLevel::Error, "OpenGL: Cannot build shader program, OpenGL hasn't been loaded\n");
+ return false;
+ }
+
ids[0] = glCreateShader(GL_VERTEX_SHADER);
len = strlen(vs);
glShaderSource(ids[0], 1, &vs, &len);
@@ -87,6 +93,12 @@ bool LinkShaderProgram(GLuint* ids)
{
int res;
+ if (!glLinkProgram)
+ {
+ Log(LogLevel::Error, "OpenGL: Cannot link shader program, OpenGL hasn't been loaded\n");
+ return false;
+ }
+
glLinkProgram(ids[2]);
glDetachShader(ids[2], ids[0]);
@@ -115,12 +127,18 @@ bool LinkShaderProgram(GLuint* ids)
void DeleteShaderProgram(GLuint* ids)
{
- glDeleteProgram(ids[2]);
+ if (glDeleteProgram)
+ { // If OpenGL isn't loaded, then there's no shader program to delete
+ glDeleteProgram(ids[2]);
+ }
}
void UseShaderProgram(GLuint* ids)
{
- glUseProgram(ids[2]);
+ if (glUseProgram)
+ { // If OpenGL isn't loaded, then there's no shader program to use
+ glUseProgram(ids[2]);
+ }
}
}