pkdawson / imgui-godot

Dear ImGui plugin for Godot 4
MIT License
492 stars 28 forks source link

Godot Editor crashes with ImGui under [Tool] nodes #81

Closed jasonswearingen closed 3 months ago

jasonswearingen commented 3 months ago

runs "in game" fine.

When creating a simple project with this as the script for the loading scene, it crashes.

using Godot;
using System;
using ImGuiNET;

[Tool]
public partial class Hello : Node3D
{
    public override void _Process(double delta)
    {
        ImGui.Begin("ImGui on Godot 4");
        ImGui.Text("hello world Test");
        ImGui.End();
    }
}

Crashes on the first line with

System.AccessViolationException
  HResult=0x80004003
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

image

Crashes the editor upon startup until rebuilding the csharp code with the ImGui lines commented out.

Ideally I would be able to use ImGui in the editor via [Tool] nodes, just like in-game.

specs:

jasonswearingen commented 3 months ago

I see in #58 the use of ToolInit(). I tried adding that:

    private bool isImGuiInit = false;
    public override void _Ready()
    {
        base._Ready();
        isImGuiInit = ImGuiGD.ToolInit();
    }

but it always returns false (including when I try recalling it from _Process()). This always returns false both in the editor and when running in debug.

jasonswearingen commented 3 months ago

I got it "working" (not crashing).... I used the addon folder from the git repo, not the releases. switching to releases now works.

image

pkdawson commented 3 months ago

Yes, using ImGui in the editor is one feature that absolutely requires the GDExtension.

https://github.com/pkdawson/imgui-godot/wiki/In%E2%80%90editor-GUI