Browse Source

Textures: Detect when using a texture that's about to be destroyed.

ocornut 5 months ago
parent
commit
131f5c57ab
2 changed files with 6 additions and 1 deletions
  1. 4 1
      imgui.cpp
  2. 2 0
      imgui_draw.cpp

+ 4 - 1
imgui.cpp

@@ -15733,7 +15733,10 @@ void ImGui::DebugNodeTexture(ImTextureData* tex)
         Checkbox("Show used rect", &cfg->ShowTextureUsedRect);
         PushStyleVar(ImGuiStyleVar_ImageBorderSize, ImMax(1.0f, g.Style.ImageBorderSize));
         ImVec2 p = GetCursorScreenPos();
-        ImageWithBg(tex->GetTexRef(), ImVec2((float)tex->Width, (float)tex->Height), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
+        if (tex->WantDestroyNextFrame)
+            Dummy(ImVec2((float)tex->Width, (float)tex->Height));
+        else
+            ImageWithBg(tex->GetTexRef(), ImVec2((float)tex->Width, (float)tex->Height), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
         if (cfg->ShowTextureUsedRect)
             GetWindowDrawList()->AddRect(ImVec2(p.x + tex->UsedRect.x, p.y + tex->UsedRect.y), ImVec2(p.x + tex->UsedRect.x + tex->UsedRect.w, p.y + tex->UsedRect.y + tex->UsedRect.h), IM_COL32(255, 0, 255, 255));
         PopStyleVar();

+ 2 - 0
imgui_draw.cpp

@@ -676,6 +676,8 @@ void ImDrawList::PushTexture(ImTextureRef tex_ref)
 {
     _TextureStack.push_back(tex_ref);
     _CmdHeader.TexRef = tex_ref;
+    if (tex_ref._TexData != NULL)
+        IM_ASSERT(tex_ref._TexData->WantDestroyNextFrame == false);
     _OnChangedTexture();
 }