1-
21#include < imgui_internal.h>
32#include " DevTools.hpp"
43#include " fonts/FeatherIcons.hpp"
@@ -189,11 +188,15 @@ void DevTools::setupFonts() {
189188 void * font, size_t realSize, float size, const ImWchar* range
190189 ) {
191190 auto & io = ImGui::GetIO ();
191+ // AddFontFromMemoryTTF assumes ownership of the passed data unless you configure it not to.
192+ // Our font data has static lifetime, so we're handling the ownership.
193+
192194 ImFontConfig config;
193- config.MergeMode = true ;
195+ config.FontDataOwnedByAtlas = false ;
194196 auto * result = io.Fonts ->AddFontFromMemoryTTF (
195- font, realSize, size, nullptr , range
197+ font, realSize, size, &config , range
196198 );
199+ config.MergeMode = true ;
197200 io.Fonts ->AddFontFromMemoryTTF (
198201 Font_FeatherIcons, sizeof (Font_FeatherIcons), size - 4 .f , &config, icon_ranges
199202 );
@@ -213,7 +216,7 @@ void DevTools::setup() {
213216
214217 IMGUI_CHECKVERSION ();
215218
216- auto ctx = ImGui::CreateContext ();
219+ ImGui::CreateContext ();
217220
218221 auto & io = ImGui::GetIO ();
219222 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
@@ -234,23 +237,27 @@ void DevTools::setup() {
234237
235238void DevTools::destroy () {
236239 if (!m_setup) return ;
237- m_setup = false ;
238- m_visible = false ;
240+ this ->show (false );
241+ auto & io = ImGui::GetIO ();
242+ io.BackendPlatformUserData = nullptr ;
243+ m_fontTexture->release ();
244+ m_fontTexture = nullptr ;
239245
240- // crashes :(
241- // ImGui::DestroyContext();
246+ ImGui::DestroyContext ();
247+ m_setup = false ;
248+ m_reloadTheme = true ;
242249}
243250
244251void DevTools::show (bool visible) {
245252 m_visible = visible;
253+
254+ auto & io = ImGui::GetIO ();
255+ io.WantCaptureMouse = visible;
256+ io.WantCaptureKeyboard = visible;
246257}
247258
248259void DevTools::toggle () {
249260 this ->show (!m_visible);
250- if (!m_visible) {
251- ImGui::GetIO ().WantCaptureMouse = false ;
252- ImGui::GetIO ().WantCaptureKeyboard = false ;
253- }
254261}
255262
256263void DevTools::sceneChanged () {
0 commit comments