Răsfoiți Sursa

Fonts: avoid both ImTextureRef fields being set simultaneously.

ocornut 5 luni în urmă
părinte
comite
a548cd9934
2 a modificat fișierele cu 5 adăugiri și 6 ștergeri
  1. 3 2
      imgui.h
  2. 2 4
      imgui_draw.cpp

+ 3 - 2
imgui.h

@@ -3426,7 +3426,7 @@ struct IMGUI_API ImTextureData
     unsigned char*      GetPixelsAt(int x, int y)   { IM_ASSERT(Pixels != NULL); return Pixels + (x + y * Width) * BytesPerPixel; }
     unsigned char*      GetPixelsAt(int x, int y)   { IM_ASSERT(Pixels != NULL); return Pixels + (x + y * Width) * BytesPerPixel; }
     int                 GetSizeInBytes() const      { return Width * Height * BytesPerPixel; }
     int                 GetSizeInBytes() const      { return Width * Height * BytesPerPixel; }
     int                 GetPitch() const            { return Width * BytesPerPixel; }
     int                 GetPitch() const            { return Width * BytesPerPixel; }
-    ImTextureRef        GetTexRef()                 { ImTextureRef tex_ref; tex_ref._TexData = this; tex_ref._TexID = TexID; return tex_ref; } // FIXME-TEXREF
+    ImTextureRef        GetTexRef()                 { ImTextureRef tex_ref; tex_ref._TexData = this; tex_ref._TexID = ImTextureID_Invalid; return tex_ref; }
     ImTextureID         GetTexID() const            { return TexID; }
     ImTextureID         GetTexID() const            { return TexID; }
 
 
     // Called by Renderer backend
     // Called by Renderer backend
@@ -3761,6 +3761,7 @@ struct ImFont
 // We added an indirection to avoid patching ImDrawCmd after texture updates but this could be a solution too.
 // We added an indirection to avoid patching ImDrawCmd after texture updates but this could be a solution too.
 inline ImTextureID ImTextureRef::GetTexID() const
 inline ImTextureID ImTextureRef::GetTexID() const
 {
 {
+    IM_ASSERT(!(_TexData != NULL && _TexID != ImTextureID_Invalid));
     return _TexData ? _TexData->TexID : _TexID;
     return _TexData ? _TexData->TexID : _TexID;
 }
 }
 
 
@@ -3768,7 +3769,7 @@ inline ImTextureID ImDrawCmd::GetTexID() const
 {
 {
     // If you are getting this assert: A renderer backend with support for ImGuiBackendFlags_RendererHasTextures (1.92)
     // If you are getting this assert: A renderer backend with support for ImGuiBackendFlags_RendererHasTextures (1.92)
     // must iterate and handle ImTextureData requests stored in ImDrawData::Textures[].
     // must iterate and handle ImTextureData requests stored in ImDrawData::Textures[].
-    ImTextureID tex_id = TexRef._TexData ? TexRef._TexData->TexID : TexRef._TexID;
+    ImTextureID tex_id = TexRef._TexData ? TexRef._TexData->TexID : TexRef._TexID; // == TexRef.GetTexID() above.
     if (TexRef._TexData != NULL)
     if (TexRef._TexData != NULL)
         IM_ASSERT(tex_id != ImTextureID_Invalid && "ImDrawCmd is referring to ImTextureData that wasn't uploaded to graphics system. Backend must call ImTextureData::SetTexID() after handling ImTextureStatus_WantCreate request!");
         IM_ASSERT(tex_id != ImTextureID_Invalid && "ImDrawCmd is referring to ImTextureData that wasn't uploaded to graphics system. Backend must call ImTextureData::SetTexID() after handling ImTextureStatus_WantCreate request!");
     return tex_id;
     return tex_id;

+ 2 - 4
imgui_draw.cpp

@@ -2615,7 +2615,6 @@ ImFontAtlas::ImFontAtlas()
     TexMaxWidth = 8192;
     TexMaxWidth = 8192;
     TexMaxHeight = 8192;
     TexMaxHeight = 8192;
     RendererHasTextures = false; // Assumed false by default, as apps can call e.g Atlas::Build() after backend init and before ImGui can update.
     RendererHasTextures = false; // Assumed false by default, as apps can call e.g Atlas::Build() after backend init and before ImGui can update.
-    TexRef._TexData = NULL;// this;
     TexNextUniqueID = 1;
     TexNextUniqueID = 1;
     FontNextUniqueID = 1;
     FontNextUniqueID = 1;
     Builder = NULL;
     Builder = NULL;
@@ -3882,9 +3881,8 @@ static void ImFontAtlasBuildSetTexture(ImFontAtlas* atlas, ImTextureData* tex)
     atlas->TexData = tex;
     atlas->TexData = tex;
     atlas->TexUvScale = ImVec2(1.0f / tex->Width, 1.0f / tex->Height);
     atlas->TexUvScale = ImVec2(1.0f / tex->Width, 1.0f / tex->Height);
     atlas->TexRef._TexData = tex;
     atlas->TexRef._TexData = tex;
-    //atlas->TexID._TexID = tex->TexID; // <-- We intentionally don't do that and leave it 0, to allow late upload.
-    ImTextureRef new_tex_ref = atlas->TexRef;
-    ImFontAtlasUpdateDrawListsTextures(atlas, old_tex_ref, new_tex_ref);
+    //atlas->TexRef._TexID = tex->TexID; // <-- We intentionally don't do that. It would be misleading and betray promise that both fields aren't set.
+    ImFontAtlasUpdateDrawListsTextures(atlas, old_tex_ref, atlas->TexRef);
 }
 }
 
 
 // Create a new texture, discard previous one
 // Create a new texture, discard previous one