Skip to content

Commit

Permalink
imgui_impl_opengl2: Add ImGui_ImplOpemGL2_NewFrame_NoAssert()
Browse files Browse the repository at this point in the history
Here I'm introducing a new method ImGui_ImplOpemGL2_NewFrame_NoAssert()
for Dear ImGui's OpenGL 2 implementation/

This is apecial edition of ImGui_ImplOpenGL2_NewFrame() for VST plugin editors.
It won't assert if OpenGL backend is not intialized, just return bool state.

This function aims at UI drawing method called on effEditIdle, without
using thread or mutex. As effEditIdle will always be triggered even when
you are closing the editor. At this time, the original
ImGui_ImplOpenGL2_NewFrame() won't continue, then crash with an
assertion.

To use in production, You must check if this method success or not before other steps,
or your editor may crash!
  • Loading branch information
AnClark committed Aug 30, 2021
1 parent c7529c8 commit abc46e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions backends/imgui_impl_opengl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ void ImGui_ImplOpenGL2_NewFrame()
ImGui_ImplOpenGL2_CreateDeviceObjects();
}

// Special edition of ImGui_ImplOpenGL2_NewFrame() for VST plugin editors.
// Won't assert if OpenGL backend is not intialized, just return bool state.
// This can make sure that you can safely call UI drawing method on effEditIdle,
// without using thread or mutex.
//
// To use in production, You must check if this method success or not before other steps,
// or your editor may crash!
bool ImGui_ImplOpenGL2_NewFrame_NoAssert()
{
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
if (!bd)
return false;

if (!bd->FontTexture)
return ImGui_ImplOpenGL2_CreateDeviceObjects();

return true;
}

static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height)
{
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill.
Expand Down
3 changes: 3 additions & 0 deletions backends/imgui_impl_opengl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyFontsTexture();
IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects();

// Special methods used by VST plugin editor
IMGUI_IMPL_API bool ImGui_ImplOpenGL2_NewFrame_NoAssert();

0 comments on commit abc46e7

Please sign in to comment.