From 503b8c20de28373f8d6c6e5837983833fc9ae234 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 2 Apr 2015 17:48:22 +0100 Subject: [PATCH] Delete font clear pointer in ImGui state to get a clear crasah instead of a dangling pointer. #181 --- imgui.cpp | 10 ++++++++++ imgui.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 51ee2e66..6f87da2b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8264,6 +8264,16 @@ ImFont::ImFont() Clear(); } +ImFont::~ImFont() +{ + // Invalidate active font so that the user gets a clear crash instead of a dangling pointer. + // If you want to delete fonts you need to do it between Render() and NewFrame(). + ImGuiState& g = *GImGui; + if (g.Font == this) + g.Font = NULL; + Clear(); +} + void ImFont::Clear() { FontSize = 0.0f; diff --git a/imgui.h b/imgui.h index d237e09e..8035090e 100644 --- a/imgui.h +++ b/imgui.h @@ -998,7 +998,7 @@ struct ImFont // Methods IMGUI_API ImFont(); - IMGUI_API ~ImFont() { Clear(); } + IMGUI_API ~ImFont(); IMGUI_API void Clear(); IMGUI_API void BuildLookupTable(); IMGUI_API const Glyph* FindGlyph(unsigned short c) const;