Skip to content

Commit

Permalink
Add some checks for programming errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Oct 27, 2023
1 parent 9b2f638 commit 2991202
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions addons/imgui-godot/ImGuiGodot/ImGuiGD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -128,6 +136,7 @@ public static void Update(double delta, Vector2 displaySize)

Internal.State.Instance.Input.Update(io);

_inProcessFrame = true;
ImGui.NewFrame();
}

Expand All @@ -137,6 +146,7 @@ public static void Render()

ImGui.UpdatePlatformWindows();
Internal.State.Instance.Renderer.RenderDrawData();
_inProcessFrame = false;
}

public static void Shutdown()
Expand Down
2 changes: 1 addition & 1 deletion src/MySecondNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2991202

Please sign in to comment.