Version/Branch of Dear ImGui:
Version: 1.89
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: MSVC
Operating System: Windows 11
My Issue:
There is a bug in imgui_impl_opengl3.cpp at line 579 that may generate the following OpenGL error:
GL_INVALID_VALUE error generated. Program handle does not refer to an object generated by OpenGL.
This error is caused by the following situation:
- Create an OpenGL shader (we will call it
123).
- Bind the shader and do some rendering
- Delete the shader as it is no longer needed. The shader is flagged for deletion but not directly deleted as it is currently bound to the state machine.
- Render the ImGui UI.
In this step, the backend will first backup the currently bound shader using glGetIntegerv(GL_CURRENT_PROGRAM, ...). This will return 123 since our shader is not deleted yet (as it is bound), but is pending deletion.
The backend will then do its internals, which includes binding its own shaders. This will unbind our shader 123 and since it is pending deletion and no longer used by OpenGL, it will actually be deleted there.
Once the backend is done with its tasks, it will attempt to rebind the previously bound shader, which is our shader 123. The problem is that in the meantime, this shader has been deleted. This call ends up binding a deleted shader and causing the mentionned OpenGL error.
A way to fix this is to check if the shader is still valid before trying to rebind it:
if (glIsProgram(last_program))
glUseProgram(last_program);
Note: This bug may also apply to other resources in the backup/restore steps.
Version/Branch of Dear ImGui:
Version: 1.89
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: MSVC
Operating System: Windows 11
My Issue:
There is a bug in imgui_impl_opengl3.cpp at line 579 that may generate the following OpenGL error:
GL_INVALID_VALUE error generated. Program handle does not refer to an object generated by OpenGL.This error is caused by the following situation:
123).In this step, the backend will first backup the currently bound shader using
glGetIntegerv(GL_CURRENT_PROGRAM, ...). This will return123since our shader is not deleted yet (as it is bound), but is pending deletion.The backend will then do its internals, which includes binding its own shaders. This will unbind our shader
123and since it is pending deletion and no longer used by OpenGL, it will actually be deleted there.Once the backend is done with its tasks, it will attempt to rebind the previously bound shader, which is our shader
123. The problem is that in the meantime, this shader has been deleted. This call ends up binding a deleted shader and causing the mentionned OpenGL error.A way to fix this is to check if the shader is still valid before trying to rebind it:
Note: This bug may also apply to other resources in the backup/restore steps.