Perform ImGui calls only when a context is available.

PiperOrigin-RevId: 865072901
Change-Id: I4b35d953df2f686d2f02f8e0aede7109729b5e04
This commit is contained in:
Haroon Qureshi
2026-02-03 15:28:25 -08:00
committed by Copybara-Service
parent 144a8a9e85
commit 1bd72428f1
2 changed files with 12 additions and 4 deletions
@@ -208,6 +208,10 @@ void GuiView::DestroyTexture(ImTextureData* data) {
}
void GuiView::UpdateRenderable() {
if (!ImGui::GetCurrentContext()) {
return;
}
// Prepare the imgui draw commands. We must call this function even if we do
// not plan on rendering anything to ensure imgui state is updated.
ImGui::Render();
+8 -4
View File
@@ -36,7 +36,9 @@ Renderer::Renderer(void* native_window) : native_window_(native_window) {
if (native_window == nullptr) {
graphics_api_context_ = CreateEglContext();
}
ImGui_ImplOpenGL3_Init();
if (ImGui::GetCurrentContext()) {
ImGui_ImplOpenGL3_Init();
}
#endif
}
@@ -117,9 +119,11 @@ void Renderer::Render(const mjModel* model, mjData* data,
// The filament backend knows how to renders the ImGui draw data. For the
// classic backend, we need to render the ImGui draw data ourselves.
#ifdef MUJOCO_RENDERER_CLASSIC_OPENGL
ImGui_ImplOpenGL3_NewFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (ImGui::GetCurrentContext()) {
ImGui_ImplOpenGL3_NewFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
#endif
if (render_to_texture) {