Browse Source

Textures: allowed backend to destroy texture while inside the NewFrame/EndFrame scope. (#8811)

ocornut 1 week ago
parent
commit
8c22b8aef6
2 changed files with 10 additions and 4 deletions
  1. 6 2
      docs/CHANGELOG.txt
  2. 4 2
      imgui.h

+ 6 - 2
docs/CHANGELOG.txt

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

+ 4 - 2
imgui.h

@@ -3491,8 +3491,10 @@ struct ImTextureData
     ImTextureID         GetTexID() const            { return TexID; }
 
     // Called by Renderer backend
-    void                SetTexID(ImTextureID tex_id)      { TexID = tex_id; }   // Call after creating or destroying the texture. Never modify TexID directly!
-    void                SetStatus(ImTextureStatus status) { Status = status; }  // Call after honoring a request. Never modify Status directly!
+    // - Call SetTexID() and SetStatus() after honoring texture requests. Never modify TexID and Status directly!
+    // - 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.
+    void    SetTexID(ImTextureID tex_id)            { TexID = tex_id; }
+    void    SetStatus(ImTextureStatus status)       { Status = status; if (status == ImTextureStatus_Destroyed && !WantDestroyNextFrame) Status = ImTextureStatus_WantCreate; }
 };
 
 //-----------------------------------------------------------------------------