From 4af84ac781bff28ca063fae6bc3d2683e502517f Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 30 Dec 2017 23:10:11 +0100 Subject: [PATCH 1/3] ImFontAtlas: Handle stb_truetype failure more gracefully, GetTexDataAsRGBA32() won't crash during conversion. (#1527) --- imgui_draw.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index b56d90cf..3de85da8 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1439,11 +1439,14 @@ void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_wid { unsigned char* pixels; GetTexDataAsAlpha8(&pixels, NULL, NULL); - TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4)); - const unsigned char* src = pixels; - unsigned int* dst = TexPixelsRGBA32; - for (int n = TexWidth * TexHeight; n > 0; n--) - *dst++ = IM_COL32(255, 255, 255, (unsigned int)(*src++)); + if (pixels) + { + TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4)); + const unsigned char* src = pixels; + unsigned int* dst = TexPixelsRGBA32; + for (int n = TexWidth * TexHeight; n > 0; n--) + *dst++ = IM_COL32(255, 255, 255, (unsigned int)(*src++)); + } } *out_pixels = (unsigned char*)TexPixelsRGBA32; @@ -1683,6 +1686,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) IM_ASSERT(font_offset >= 0); if (!stbtt_InitFont(&tmp.FontInfo, (unsigned char*)cfg.FontData, font_offset)) { + atlas->TexWidth = atlas->TexHeight = 0; // Reset output on failure ImGui::MemFree(tmp_array); return false; } From 170bcb2d7c247595761bfb07b36755aa6541f4cf Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 29 Dec 2017 20:56:52 +0100 Subject: [PATCH 2/3] Internals: NewFrame: Shuffled some code around (to minimize upcoming patches) --- imgui.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4b8f8aa4..b9ceb11d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2276,15 +2276,16 @@ void ImGui::NewFrame() if (!g.Initialized) Initialize(); + g.Time += g.IO.DeltaTime; + g.FrameCount += 1; + g.TooltipOverrideCount = 0; + g.WindowsActiveCount = 0; + SetCurrentFont(GetDefaultFont()); IM_ASSERT(g.Font->IsLoaded()); g.DrawListSharedData.ClipRectFullscreen = ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y); g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol; - g.Time += g.IO.DeltaTime; - g.FrameCount += 1; - g.TooltipOverrideCount = 0; - g.WindowsActiveCount = 0; g.OverlayDrawList.Clear(); g.OverlayDrawList.PushTextureID(g.IO.Fonts->TexID); g.OverlayDrawList.PushClipRectFullScreen(); From 561e9f286eee47f3a651f2bb3a1f6d021179e7ee Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 2 Jan 2018 10:46:20 -0500 Subject: [PATCH 3/3] Fix a memory leak of ImGuiColumnsSet's Columns vector. ImVector doesn't call destructors. --- imgui.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index b9ceb11d..2b6b699a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1876,6 +1876,8 @@ ImGuiWindow::~ImGuiWindow() { IM_DELETE(DrawList); IM_DELETE(Name); + for (int i = 0; i != ColumnsStorage.Size; i++) + ColumnsStorage[i].~ImGuiColumnsSet(); } ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end)