From 9056711aa94bf45796302ad5508fc178844e1c30 Mon Sep 17 00:00:00 2001 From: 0xA11CE613 Date: Sat, 1 Nov 2025 11:47:54 +0530 Subject: [PATCH] backends/opengl3: Always validate texture before uploading data * The key addition is checking glIsTexture() before attempting to update. * This will prevent a crash in android platforms using opengl3 by catching invalid texture handles before they reach the driver, and will automatically trigger texture recreation if needed. Signed-off-by: 0xA11CE613 --- backends/imgui_impl_opengl3.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index 3e0e265b1cc0..b39d088a245c 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -723,6 +723,11 @@ static void ImGui_ImplOpenGL3_DestroyTexture(ImTextureData* tex) void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex) { + if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0) { + ImGui_ImplOpenGL3_DestroyTexture(tex); + return; + } + // FIXME: Consider backing up and restoring if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates) { @@ -770,6 +775,15 @@ void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex) GL_CALL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture)); GLuint gl_tex_id = (GLuint)(intptr_t)tex->TexID; + + GLint is_texture = 0; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &is_texture); + if (!glIsTexture(gl_tex_id)) { + // Texture was destroyed, mark for recreation + tex->SetStatus(ImTextureStatus_WantCreate); + return; + } + GL_CALL(glBindTexture(GL_TEXTURE_2D, gl_tex_id)); #if GL_UNPACK_ROW_LENGTH // Not on WebGL/ES GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->Width)); @@ -793,8 +807,6 @@ void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex) tex->SetStatus(ImTextureStatus_OK); GL_CALL(glBindTexture(GL_TEXTURE_2D, last_texture)); // Restore state } - else if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0) - ImGui_ImplOpenGL3_DestroyTexture(tex); } // If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.