Skip to content

Commit 8c22b8a

Browse files
committed
Textures: allowed backend to destroy texture while inside the NewFrame/EndFrame scope. (#8811)
1 parent fc4105c commit 8c22b8a

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

docs/CHANGELOG.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ Other Changes:
6969
- Misc: Debuggers: added type formatters for the LLDB debuggers (e.g. Xcode,
7070
Android Studio & more) to provide nicer display for ImVec2, ImVec4, ImVector etc.
7171
See misc/debuggers/ for details. (#8950) [@mentlerd]
72-
- Textures: fixed a crash if a texture marked as _WantDestroy by a backend after
72+
- Textures: fixed a crash if texture status is set to _WantDestroy by a backend after
7373
it had already been destroyed. This would typically happen when calling backend's
7474
ImGui_ImplXXXX_InvalidateDeviceObjects() helpers twice in a row. (#8977, #8811)
75+
- Textures: allowed backend to destroy texture while inside the NewFrame/EndFrame
76+
scope. Basically if a backend decide to destroy a texture that we didn't request
77+
to destroy (for e.g. freeing resources) the texture is immediately set to
78+
a _WantCreate status again. (#8811)
7579
- Textures: fixed an issue preventing multi-contexts sharing a ImFontAtlas from
7680
being possible to destroy in any order.
7781
- Textures: fixed not updating ImTextureData's RefCount when destroying a context
@@ -101,7 +105,7 @@ Other Changes:
101105
CustomShaderVertCreateInfo and CustomShaderFragCreateInfo. (#8585, #8271) [@johan0A]
102106
- Backends: DX9,DX10,DX11,DX12,Metal,Vulkan,WGPU,SDLRenderer2,SDLRenderer3:
103107
ensure that a texture in _WantDestroy state always turn to _Destroyed even
104-
if your underlying graphics data was already destroyed.
108+
if your underlying graphics data was already destroyed. (#8977)
105109
- Examples: SDL2+DirectX11: Try WARP software driver if hardware driver is
106110
not available. (#5924, #5562)
107111
- Examples: SDL3+DirectX11: Added SDL3+DirectX11 example. (#8956, #8957) [@tomaz82]

imgui.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,8 +3491,10 @@ struct ImTextureData
34913491
ImTextureID GetTexID() const { return TexID; }
34923492

34933493
// Called by Renderer backend
3494-
void SetTexID(ImTextureID tex_id) { TexID = tex_id; } // Call after creating or destroying the texture. Never modify TexID directly!
3495-
void SetStatus(ImTextureStatus status) { Status = status; } // Call after honoring a request. Never modify Status directly!
3494+
// - Call SetTexID() and SetStatus() after honoring texture requests. Never modify TexID and Status directly!
3495+
// - A backend may decide to destroy a texture that we did not request to destroy, which is fine (e.g. freeing resources), but we immediately set the texture back in _WantCreate mode.
3496+
void SetTexID(ImTextureID tex_id) { TexID = tex_id; }
3497+
void SetStatus(ImTextureStatus status) { Status = status; if (status == ImTextureStatus_Destroyed && !WantDestroyNextFrame) Status = ImTextureStatus_WantCreate; }
34963498
};
34973499

34983500
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)