From ad8ef3ec109a6c2aa086775a1fccd7d913055b8a Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 5 Sep 2020 17:26:51 -0700 Subject: [PATCH] fix handling of glGenTextures failure MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit According to the OpenGL docs, glGenTextures indicates failure not through returning a value in its out parameter but rather via the glGetError API. Moreover it could not actually indicate failure in the way this call site was expecting because the out parameter is unsigned, not signed. This issue was identified while investigating the cause of the following compiler warning: glcomptexture.c: In function ‘glCompSetAddNewTexture’: glcomptexture.c:45:12: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] if (t->id < 0) /*for some opengl based error , texture couldnt be created */ ^ --- CHANGELOG.md | 1 + lib/glcomp/glcomptexture.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 701f694f6..e2544b93c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - "Warning! PATH too long installer unable to modify PATH!" using CMake Windows installer and PATH length > 1024 #1770 - gvedit -? gives "option - unrecognized - ignored" instead of showing usage #1813 - lefty is not built for Windows (fixed for MSBuild builds only) #1818 +- a failure to detect OpenGL glGenTextures() errors has been corrected ## [2.44.1] - 2020-06-29 diff --git a/lib/glcomp/glcomptexture.c b/lib/glcomp/glcomptexture.c index 872a7ceb8..d3402bf3c 100644 --- a/lib/glcomp/glcomptexture.c +++ b/lib/glcomp/glcomptexture.c @@ -42,9 +42,11 @@ static glCompTex *glCompSetAddNewTexture(glCompSet * s, int width, glEnable(GL_DEPTH_TEST); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &t->id); //get next id - if (t->id < 0) /*for some opengl based error , texture couldnt be created */ + if (glGetError() != GL_NO_ERROR) { /*for some opengl based error , texture couldnt be created */ + /* drain the OpenGL error queue */ + while (glGetError() != GL_NO_ERROR); Er = 1; - else { + } else { glBindTexture(GL_TEXTURE_2D, t->id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); -- 2.40.0