floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.55k stars 469 forks source link

stale default framebuffer bound at end of offscreen pass #935

Closed danielchasehooper closed 4 months ago

danielchasehooper commented 8 months ago

in an application with multiple gl windows consider this situation:

  1. window 1 draws into its default framebuffer (via sg_desc.context.gl.default_framebuffer_cb)
  2. window 1 is closed, it's framebuffer is destroyed
  3. window 2 performs its first offscreen pass and then calls sg_pass_end()
  4. in _sg_gl_end_pass, glBindFramebuffer(GL_FRAMEBUFFER, _sg.gl.cur_context->default_framebuffer) is called with a framebuffer that is now invalid. (sg_desc.context.gl.default_framebuffer_cb isn't called at the start of an offscreen pass)

-> crash in _SG_GL_CHECK_ERROR()

danielchasehooper commented 5 months ago

@floooh any thoughts on this? we've had to work around it by setting _sg.gl.cur_context->default_framebuffer before the first pass

floooh commented 5 months ago

My plan was to implement https://github.com/floooh/sokol/issues/904 as a "proper" but breaking fix (it's most likely the next "big thing" after catching up with a couple smaller PRs, but I can't promise an ETA).

I guess it might make sense to implement your solution in the meantime.

Can you provide a PR (or point me to an existing one)?

danielchasehooper commented 5 months ago

It's unclear how to best fix in a general way. Could we just not call glBindFramebuffer at the end of the pass?

otherwise we would need to call sg_desc.context.gl.default_framebuffer_cb at the end of every pass

floooh commented 5 months ago

Could we just not call glBindFramebuffer at the end of the pass?

I'll need to do some git archeology whether there's a specific reason for that glBindFramebuffer, but that might work, yeah.

floooh commented 4 months ago

I think this is fixed now with the new render-pass API.