Browse Source

ImFontAtlas: Fixed calling Clear() and rebuilding (broken in 3fe2ecfd4cd34367b505fba38941217a3cc89f1d) thanks @pdoane @mikesart

omar 8 years ago
parent
commit
09f6f564d9
2 changed files with 4 additions and 1 deletions
  1. 0 1
      imgui.h
  2. 4 0
      imgui_draw.cpp

+ 0 - 1
imgui.h

@@ -1432,7 +1432,6 @@ struct ImFontAtlas
 
 
     IMGUI_API int       AddCustomRectRegular(unsigned int id, int width, int height);                                                                   // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
     IMGUI_API int       AddCustomRectRegular(unsigned int id, int width, int height);                                                                   // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
     IMGUI_API int       AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0));   // Id needs to be < 0x10000 to register a rectangle to map into a specific font.
     IMGUI_API int       AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0));   // Id needs to be < 0x10000 to register a rectangle to map into a specific font.
-    IMGUI_API void      ClearCustomRects();
     IMGUI_API void      CalcCustomRectUV(const CustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max);
     IMGUI_API void      CalcCustomRectUV(const CustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max);
     const CustomRect*   GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; }
     const CustomRect*   GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; }
 
 

+ 4 - 0
imgui_draw.cpp

@@ -1134,6 +1134,8 @@ void    ImFontAtlas::ClearInputData()
         }
         }
     ConfigData.clear();
     ConfigData.clear();
     CustomRects.clear();
     CustomRects.clear();
+    for (int n = 0; n < IM_ARRAYSIZE(CustomRectIds); n++)
+        CustomRectIds[n] = -1;
 }
 }
 
 
 void    ImFontAtlas::ClearTexData()
 void    ImFontAtlas::ClearTexData()
@@ -1597,6 +1599,8 @@ void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* pack_context_opaq
     stbrp_context* pack_context = (stbrp_context*)pack_context_opaque;
     stbrp_context* pack_context = (stbrp_context*)pack_context_opaque;
 
 
     ImVector<ImFontAtlas::CustomRect>& user_rects = atlas->CustomRects;
     ImVector<ImFontAtlas::CustomRect>& user_rects = atlas->CustomRects;
+    IM_ASSERT(user_rects.Size >= 1); // We expect at least the default custom rects to be registered, else something went wrong.
+
     ImVector<stbrp_rect> pack_rects;
     ImVector<stbrp_rect> pack_rects;
     pack_rects.resize(user_rects.Size);
     pack_rects.resize(user_rects.Size);
     memset(pack_rects.Data, 0, sizeof(stbrp_rect) * user_rects.Size);
     memset(pack_rects.Data, 0, sizeof(stbrp_rect) * user_rects.Size);