bgfx: 22-windows example using OpenGL renderer crashes on Windows10

Fatal error info: Code 0(DebugCheck) Message: glPopDebugGroup(); GL Error 0x504 <GLenum?> Error points to renderer_gl.cpp line 6515.

Switching to DX11 backend, works as expected.

It seems to be related to bgfx::setViewFrameBuffer. Commenting out the call in the update function, the app does not crash. Creates the window properly and destroys it as well without issues.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (15 by maintainers)

Most upvoted comments

Seems like when bgfx::setViewFrameBuffer is called with a valid framebuffer, somehow the Debug Groups end up popping one time too many at line 6515(tries to pop default debug group, which is why it throws the error).

Ok I think I found the problem.

There actually is a context switch in setFrameBuffer (L6551), causing BGFX_GL_PROFILER_END() (L6559) to pop an empty debug group stack. For some reason I missed the fact that each swap chain has its own GL context (thought it only stored the window surface). So the call looks like it matches the call to BGFX_GL_PROFILER_BEGIN_LITERAL() (L6402) from the top of the submit() function, but it does not.

The fix is to close the debug group before calling setFrameBuffer and then open up another debug group, like so:

if (item > 1)
{
	profiler.end();
}

BGFX_GL_PROFILER_END();

if (_render->m_view[view].m_fbh.idx != fbh.idx)
{
	fbh = _render->m_view[view].m_fbh;
	resolutionHeight = _render->m_resolution.height;
	resolutionHeight = setFrameBuffer(fbh, resolutionHeight, discardFlags);
}

setViewType(view, "  ");
BGFX_GL_PROFILER_BEGIN(view, kColorView);

profiler.begin(view);

This fixes the example 22-windows for me on Linux.