Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

SDL_RenderDrawLines ERROR :GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute 1 #134

Open
DarthGandalf opened this issue Dec 14, 2020 · 3 comments

Comments

@DarthGandalf
Copy link

DarthGandalf commented Dec 14, 2020

I'm using SDL_RenderDrawLines.

I cannot reproduce the issue myself, but one of users sees that message in browser console, and the lines are not drawn.

https://www.asokolov.org/advent-of-code/2020/day12.html is the deployed version of it.

screenshot

However, sometimes the lines are drawn correctly, as can be seen here. First it shows correctly, then just stops. With a different input (e.g. this one) it stops drawing at a different point.

The user tried it with Chrome and Firefox, on Windows, with the same result.

This workaround helps: SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");

Source code:

@blankdvth
Copy link

blankdvth commented Dec 14, 2020

Hey, I'm that user and I'd like to point out that your input didn't work either on the website (same issue, shows for a bit then stops, except this time it shows even less). The click here (?renderer=software) fixes it for both your and my input. Seems that the glitch occurs regardless of the input on the normal renderer.

@DarthGandalf
Copy link
Author

Oh, okay, I've updated the description, thanks.

@Daft-Freak
Copy link
Member

Okay, I can reproduce on Windows, but not Linux (browser doesn't seem to matter).

Looks like there's a bug in the GLES renderer. Attribute 1 is texture coordinates, which should be disabled when rendering lines. Something is causing the state to get a bit out of sync, resulting in that not happening.

This patch seems to fix it, but don't know how correct it is... (Don't really know the renderer code, usually stick to the backend)

diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 028227f75..bde9d8ab3 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -983,17 +983,17 @@ SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_I
         data->drawstate.cliprect_dirty = SDL_FALSE;
     }
 
-    if (texture != data->drawstate.texture) {
-        if ((texture != NULL) != data->drawstate.texturing) {
-            if (texture == NULL) {
-                data->glDisableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
-                data->drawstate.texturing = SDL_FALSE;
-            } else {
-                data->glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
-                data->drawstate.texturing = SDL_TRUE;
-            }
+    if ((texture != NULL) != data->drawstate.texturing) {
+        if (texture == NULL) {
+            data->glDisableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
+            data->drawstate.texturing = SDL_FALSE;
+        } else {
+            data->glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
+            data->drawstate.texturing = SDL_TRUE;
         }
+    }
 
+    if (texture != data->drawstate.texture) {
         if (texture) {
             GLES2_TextureData *tdata = (GLES2_TextureData *) texture->driverdata;
             if (tdata->yuv) {

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants