From 09f6f564d91ae061bfe35763c8e738e9f7255774 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 27 Sep 2017 11:21:42 +0200 Subject: [PATCH] ImFontAtlas: Fixed calling Clear() and rebuilding (broken in 3fe2ecfd4cd34367b505fba38941217a3cc89f1d) thanks @pdoane @mikesart --- imgui.h | 1 - imgui_draw.cpp | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 185a31355..48eda19c8 100644 --- a/imgui.h +++ b/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 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); const CustomRect* GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index aee9374d5..736476891 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1134,6 +1134,8 @@ void ImFontAtlas::ClearInputData() } ConfigData.clear(); CustomRects.clear(); + for (int n = 0; n < IM_ARRAYSIZE(CustomRectIds); n++) + CustomRectIds[n] = -1; } void ImFontAtlas::ClearTexData() @@ -1597,6 +1599,8 @@ void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* pack_context_opaq stbrp_context* pack_context = (stbrp_context*)pack_context_opaque; ImVector& 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 pack_rects; pack_rects.resize(user_rects.Size); memset(pack_rects.Data, 0, sizeof(stbrp_rect) * user_rects.Size);