浏览代码

Fonts: fixed NewFrame() when atlas builder has been created but fonts not added. Fixed GetCustomRect() after atlas clear.

ocornut 2 月之前
父节点
当前提交
e1481a731d
共有 2 个文件被更改,包括 3 次插入1 次删除
  1. 1 1
      imgui.cpp
  2. 2 0
      imgui_draw.cpp

+ 1 - 1
imgui.cpp

@@ -8668,7 +8668,7 @@ ImFont* ImGui::GetDefaultFont()
 {
 {
     ImGuiContext& g = *GImGui;
     ImGuiContext& g = *GImGui;
     ImFontAtlas* atlas = g.IO.Fonts;
     ImFontAtlas* atlas = g.IO.Fonts;
-    if (atlas->Builder == NULL)
+    if (atlas->Builder == NULL || atlas->Fonts.Size == 0)
         ImFontAtlasBuildMain(atlas);
         ImFontAtlasBuildMain(atlas);
     return g.IO.FontDefault ? g.IO.FontDefault : atlas->Fonts[0];
     return g.IO.FontDefault ? g.IO.FontDefault : atlas->Fonts[0];
 }
 }

+ 2 - 0
imgui_draw.cpp

@@ -4362,6 +4362,8 @@ ImTextureRect* ImFontAtlasPackGetRectSafe(ImFontAtlas* atlas, ImFontAtlasRectId
     if (id == ImFontAtlasRectId_Invalid)
     if (id == ImFontAtlasRectId_Invalid)
         return NULL;
         return NULL;
     int index_idx = ImFontAtlasRectId_GetIndex(id);
     int index_idx = ImFontAtlasRectId_GetIndex(id);
+    if (atlas->Builder == NULL)
+        ImFontAtlasBuildInit(atlas);
     ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
     ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
     if (index_idx >= builder->RectsIndex.Size)
     if (index_idx >= builder->RectsIndex.Size)
         return NULL;
         return NULL;