1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-09 23:54:20 +00:00

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 <mprabhat774@gmail.com>
This commit is contained in:
0xA11CE613 2025-11-01 11:47:54 +05:30
parent 823ccc274e
commit 9056711aa9

View file

@ -723,6 +723,11 @@ static void ImGui_ImplOpenGL3_DestroyTexture(ImTextureData* tex)
void ImGui_ImplOpenGL3_UpdateTexture(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 // FIXME: Consider backing up and restoring
if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates) 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)); GL_CALL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture));
GLuint gl_tex_id = (GLuint)(intptr_t)tex->TexID; 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)); GL_CALL(glBindTexture(GL_TEXTURE_2D, gl_tex_id));
#if GL_UNPACK_ROW_LENGTH // Not on WebGL/ES #if GL_UNPACK_ROW_LENGTH // Not on WebGL/ES
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->Width)); GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->Width));
@ -793,8 +807,6 @@ void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex)
tex->SetStatus(ImTextureStatus_OK); tex->SetStatus(ImTextureStatus_OK);
GL_CALL(glBindTexture(GL_TEXTURE_2D, last_texture)); // Restore state 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. // 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.