Window#gl segfaults with shader when deferring drawing #133

Spooner opened this Issue Jul 12, 2012 · 2 comments

2 participants


Minimal test-case

You need to gem install opengl and have LargeStar.png in the appropriate path (or change #media_path method)

The Gosu Library member

Does it crash in the same way if you comment out all the shaders? Calling Image#draw in gl blocks is not supported. gl blocks are run when Gosu loops over the rendering queue in Z order, Image#draw inserts a quad right into this queue.

In the absence of zImmediate the only clean way would be to complete your duplication of Image#draw inside the GL block. Not just select the texture, but also call glVertex or any modern equivalent of it.

But who cares about clean. :D Since Gosu does not reset the current shader, you can simply do this for now:

# z must be exactly the same value in these three calls so that they will be executed consecutively
gl(z) { glUseProgram @program; glActiveTexture GL_TEXTURE0 }
@star.draw x, y, z
gl(z) { glUseProgram 0 }

The middle case (shader and Image#draw in gl(nil)) works fine as does running shaders & draw entierly outside of a gl block. I know they are not guaranteed to work, but they do right now.

I have changed my test case to use your workaround and it works fine! I'll update Ashton - I just needed something that worked, so that is excellent, even if not, perhaps as perfect as it could be.

@jlnr jlnr modified the milestone: 1.0 May 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment