Skip to content

Commit 9056711

Browse files
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 <[email protected]>
1 parent 823ccc2 commit 9056711

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

backends/imgui_impl_opengl3.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,11 @@ static void ImGui_ImplOpenGL3_DestroyTexture(ImTextureData* tex)
723723

724724
void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex)
725725
{
726+
if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0) {
727+
ImGui_ImplOpenGL3_DestroyTexture(tex);
728+
return;
729+
}
730+
726731
// FIXME: Consider backing up and restoring
727732
if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates)
728733
{
@@ -770,6 +775,15 @@ void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex)
770775
GL_CALL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
771776

772777
GLuint gl_tex_id = (GLuint)(intptr_t)tex->TexID;
778+
779+
GLint is_texture = 0;
780+
glGetIntegerv(GL_TEXTURE_BINDING_2D, &is_texture);
781+
if (!glIsTexture(gl_tex_id)) {
782+
// Texture was destroyed, mark for recreation
783+
tex->SetStatus(ImTextureStatus_WantCreate);
784+
return;
785+
}
786+
773787
GL_CALL(glBindTexture(GL_TEXTURE_2D, gl_tex_id));
774788
#if GL_UNPACK_ROW_LENGTH // Not on WebGL/ES
775789
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->Width));
@@ -793,8 +807,6 @@ void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex)
793807
tex->SetStatus(ImTextureStatus_OK);
794808
GL_CALL(glBindTexture(GL_TEXTURE_2D, last_texture)); // Restore state
795809
}
796-
else if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0)
797-
ImGui_ImplOpenGL3_DestroyTexture(tex);
798810
}
799811

800812
// 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.

0 commit comments

Comments
 (0)