libobs-opengl: Fix gl_error_to_str

Tweaked function to address some issues: compiler warnings, skipped
entries, and type safety.
This commit is contained in:
jpark37 2019-08-12 08:05:38 -07:00
parent 444991ba21
commit 4aaef353d4

View File

@ -17,9 +17,12 @@
#pragma once
static char *gl_error_to_str(GLenum errorcode)
static const char *gl_error_to_str(GLenum errorcode)
{
static void *err_to_str[][2] = {
static const struct {
GLenum error;
const char *str;
} err_to_str[] = {
{
GL_INVALID_ENUM,
"GL_INVALID_ENUM",
@ -48,17 +51,12 @@ static char *gl_error_to_str(GLenum errorcode)
GL_STACK_OVERFLOW,
"GL_STACK_OVERFLOW",
},
{
NULL,
"Unknown",
},
};
int i = 0;
while ((GLenum)err_to_str[i][0] != errorcode ||
err_to_str[i][0] == NULL) {
i += 2;
for (size_t i = 0; i < sizeof(err_to_str) / sizeof(*err_to_str); i++) {
if (err_to_str[i].error == errorcode)
return err_to_str[i].str;
}
return err_to_str[i][1];
return "Unknown";
}
/*