britzl / extension-imgui

Dear ImGUI extension for Defold
MIT License
58 stars 19 forks source link

Crash when combining meshes with Dear ImGUI #22

Closed britzl closed 2 years ago

britzl commented 2 years ago

From the Defold repo: https://github.com/defold/defold/issues/6281

dapetcu21 commented 2 years ago

I think I have some more info about this. It crashes for me in a very particular hard-to-create-a-simple-repro-case, way too. In imgui_imple_opengl3.cpp ImGUI is saving all the OpenGL state, doing its thing then restoring it back.

After some debugging, the particular line that generates an OpenGL error that propagates all the way to the glGetError() call after glfwSwapBuffers in dmGraphics::FlipOpenGL is part of that restore state block:

glUseProgram(last_program);

My guess is that Defold uses some resources (shaders, texture, VBOs, whatever), then destroys them (which would explain #23), they remain bound (not really a problem if they're not going to be subsequently used in a draw call), but then ImGUI tries to rebind them which does cause an error.

I honestly think a quick and dirty solution like clearing the OpenGL error with glGetError() after the calls to ImGUI NewFrame and Draw would be perfectly fine. (maybe not do it if GL validation is disabled engine-wide)

britzl commented 2 years ago

It's a likely explanation for the crash! Nice detective work.