Преглед изворни кода

Shutdown() freeing a few extra vectors so they don't have to freed by destruction #169

ocornut пре 10 година
родитељ
комит
92a22ab35f
2 измењених фајлова са 20 додато и 9 уклоњено
  1. 19 9
      imgui.cpp
  2. 1 0
      imgui.h

+ 19 - 9
imgui.cpp

@@ -1975,8 +1975,6 @@ void ImGui::Shutdown()
     }
     g.Windows.clear();
     g.CurrentWindowStack.clear();
-    g.RenderDrawLists.clear();
-    g.CursorDrawList.Clear();
     g.FocusedWindow = NULL;
     g.HoveredWindow = NULL;
     g.HoveredRootWindow = NULL;
@@ -1989,26 +1987,29 @@ void ImGui::Shutdown()
     g.ColorModifiers.clear();
     g.StyleModifiers.clear();
     g.FontStack.clear();
+    g.RenderDrawLists.clear();
+    g.RenderSortedWindows.clear();
+    g.CursorDrawList.ClearFreeMemory();
     g.ColorEditModeStorage.Clear();
-    if (g.LogFile && g.LogFile != stdout)
-    {
-        fclose(g.LogFile);
-        g.LogFile = NULL;
-    }
-    g.IO.Fonts->Clear();
-
     if (g.PrivateClipboard)
     {
         ImGui::MemFree(g.PrivateClipboard);
         g.PrivateClipboard = NULL;
     }
 
+    if (g.LogFile && g.LogFile != stdout)
+    {
+        fclose(g.LogFile);
+        g.LogFile = NULL;
+    }
     if (g.LogClipboard)
     {
         g.LogClipboard->~ImGuiTextBuffer();
         ImGui::MemFree(g.LogClipboard);
     }
 
+    g.IO.Fonts->Clear();
+
     g.Initialized = false;
 }
 
@@ -7245,6 +7246,15 @@ void ImDrawList::Clear()
     texture_id_stack.resize(0);
 }
 
+void ImDrawList::ClearFreeMemory()
+{
+    commands.clear();
+    vtx_buffer.clear();
+    vtx_write = NULL;
+    clip_rect_stack.clear();
+    texture_id_stack.clear();
+}
+
 void ImDrawList::AddDrawCmd()
 {
     ImDrawCmd draw_cmd;

+ 1 - 0
imgui.h

@@ -865,6 +865,7 @@ struct ImDrawList
 
     ImDrawList() { Clear(); }
     IMGUI_API void  Clear();
+    IMGUI_API void  ClearFreeMemory();
     IMGUI_API void  PushClipRect(const ImVec4& clip_rect);          // Scissoring. The values are x1, y1, x2, y2.
     IMGUI_API void  PushClipRectFullScreen();
     IMGUI_API void  PopClipRect();