Fix texture ID collisions in ImguiBridge
Texture IDs were assigned using textures_.size() + 1, which is not monotonic: after erasures the map shrinks and previously used IDs can be reassigned to new textures. This causes multiple ImGui images to reference the same underlying Filament texture, rendering them all with the same pixel data. This fix replaces the size-based scheme with a monotonically increasing counter (next_tex_id_) that never reuses IDs. PiperOrigin-RevId: 906214496 Change-Id: I5a388861ad9565c8e00e27b39cc9c76c9750ca1e
This commit is contained in:
committed by
Copybara-Service
parent
b643f50b2a
commit
3a5a48b9f9
@@ -72,7 +72,7 @@ uintptr_t ImguiBridge::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
|
||||
|
||||
// Assign a new texture ID.
|
||||
if (tex_id == 0) {
|
||||
tex_id = textures_.size() + 1;
|
||||
tex_id = next_tex_id_++;
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture>& texture = textures_[tex_id];
|
||||
@@ -123,7 +123,7 @@ void ImguiBridge::CreateTexture(ImTextureData* data) {
|
||||
config.format = mjPIXEL_FORMAT_RGBA8;
|
||||
config.color_space = mjCOLORSPACE_LINEAR;
|
||||
|
||||
const uintptr_t tex_id = textures_.size() + 1;
|
||||
const uintptr_t tex_id = next_tex_id_++;
|
||||
textures_[tex_id] =
|
||||
std::make_unique<Texture>(scene_view_->GetEngine(), config);
|
||||
data->SetTexID((ImTextureID)tex_id);
|
||||
|
||||
@@ -64,6 +64,7 @@ class ImguiBridge {
|
||||
std::vector<std::unique_ptr<Renderable>> renderables_;
|
||||
std::vector<std::unique_ptr<Mesh>> meshes_;
|
||||
std::unordered_map<uintptr_t, std::unique_ptr<Texture>> textures_;
|
||||
uintptr_t next_tex_id_ = 1;
|
||||
};
|
||||
|
||||
// Draws text at the given screen coordinates in clip space (i.e. [-1,-1,-1] to
|
||||
|
||||
Reference in New Issue
Block a user