diff --git a/addons/imgui-godot/ImGuiGodot/ImGuiGD.cs b/addons/imgui-godot/ImGuiGodot/ImGuiGD.cs index 1c74ae7..39ddf0d 100644 --- a/addons/imgui-godot/ImGuiGodot/ImGuiGD.cs +++ b/addons/imgui-godot/ImGuiGodot/ImGuiGD.cs @@ -36,6 +36,9 @@ public static float Scale get => _scale; set { + if (_inProcessFrame) + throw new InvalidOperationException("scale cannot be changed during process frame"); + if (_scale != value && value >= 0.25f) { _scale = value; @@ -45,6 +48,8 @@ public static float Scale } private static float _scale = 1.0f; + private static bool _inProcessFrame = false; + public static IntPtr BindTexture(Texture2D tex) { return (IntPtr)tex.GetRid().Id; @@ -117,6 +122,9 @@ public static void AddFontDefault() public static void RebuildFontAtlas() { + if (_inProcessFrame) + throw new InvalidOperationException("fonts cannot be changed during process frame"); + Internal.State.Instance.Fonts.RebuildFontAtlas(ScaleToDpi ? Scale * DpiFactor : Scale); } @@ -128,6 +136,7 @@ public static void Update(double delta, Vector2 displaySize) Internal.State.Instance.Input.Update(io); + _inProcessFrame = true; ImGui.NewFrame(); } @@ -137,6 +146,7 @@ public static void Render() ImGui.UpdatePlatformWindows(); Internal.State.Instance.Renderer.RenderDrawData(); + _inProcessFrame = false; } public static void Shutdown() diff --git a/src/MySecondNode.cs b/src/MySecondNode.cs index a62b1c9..492a0b0 100644 --- a/src/MySecondNode.cs +++ b/src/MySecondNode.cs @@ -133,7 +133,7 @@ private void OnImGuiLayout() if (ImGui.RadioButton($"{s:0.00}", _scale == s)) { _scale = s; - CallDeferred("OnScaleChanged"); + CallDeferred(nameof(OnScaleChanged)); } if (i < 5) ImGui.SameLine();