Skip to content

Commit fa2477d

Browse files
[Editor] Fix ImGuiProxy memory leak with fonts;
1 parent 11eb3ba commit fa2477d

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

Engine/Staple.Editor/ImGuiProxy.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ internal class ImGuiProxy
3131

3232
public ImFontPtr headerFont;
3333

34+
private byte[] editor;
35+
private byte[] header;
3436
private bool frameBegun = false;
3537
private bool destroyed = false;
3638

@@ -97,6 +99,11 @@ public bool Initialize()
9799
var io = ImGui.GetIO();
98100
var platformIO = ImGui.GetPlatformIO();
99101

102+
io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset |
103+
ImGuiBackendFlags.RendererHasTextures;
104+
105+
io.ConfigWindowsMoveFromTitleBarOnly = true;
106+
100107
unsafe
101108
{
102109
var setPtr = Marshal.GetFunctionPointerForDelegate(SetClipboardText);
@@ -106,17 +113,10 @@ public bool Initialize()
106113
platformIO.PlatformSetClipboardTextFn = (void*)setPtr;
107114
platformIO.PlatformGetClipboardTextFn = (void*)getPtr;
108115
platformIO.PlatformClipboardUserData = (void *)nint.Zero;
109-
110-
io.Fonts.AddFontDefault();
111116
}
112117

113-
io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset |
114-
ImGuiBackendFlags.RendererHasTextures;
115-
116-
io.ConfigWindowsMoveFromTitleBarOnly = true;
117-
118-
var editor = Convert.FromBase64String(FontData.IntelOneMonoMedium);
119-
var header = Convert.FromBase64String(FontData.IntelOneMonoBold);
118+
editor = Convert.FromBase64String(FontData.IntelOneMonoMedium);
119+
header = Convert.FromBase64String(FontData.IntelOneMonoBold);
120120

121121
unsafe
122122
{
@@ -132,6 +132,8 @@ public bool Initialize()
132132
{
133133
headerFont = io.Fonts.AddFontFromMemoryTTF(ptr, header.Length, 22);
134134
}
135+
136+
io.FontDefault = editorFont;
135137
}
136138

137139
var programPath = $"Hidden/Shaders/UI/ocornut_imgui.{AssetSerialization.ShaderExtension}";
@@ -349,8 +351,6 @@ public void BeginFrame()
349351

350352
ImGuizmo.BeginFrame();
351353

352-
ImGui.PushFont(editorFont, 20);
353-
354354
frameBegun = true;
355355
}
356356

@@ -365,8 +365,6 @@ public void EndFrame()
365365
{
366366
frameBegun = false;
367367

368-
ImGui.PopFont();
369-
370368
ImGui.Render();
371369

372370
Render(ImGui.GetDrawData());

0 commit comments

Comments
 (0)