HexaEngine / Hexa.NET.ImGui

A .NET wrapper for the Dear ImGui.
Other
58 stars 5 forks source link

Can't make ImPlot to work, AccessViolationException #11

Closed Aberro closed 1 month ago

Aberro commented 1 month ago

I've been trying different overloads of PlotLine, but all of them fail with AccessViolationException. And there's just too many overloads to check all of them, VS doesn't display a tooltip with overloads, decompilation takes minutes, and even looking at decompiled ImPlot code makes my PC burn.

The code I'm using is:

    private double[] x_axis = new double[512];
    private double[] P_left = new double[512];
    private double[] P_right = new double[512];
    public PressureEqualization()
    {
        for(int i = 0; i < x_axis.Length; i++)
        {
            x_axis[i] = i / 512d;
            P_left[i] = 0.5 + 0.5 * Math.Sin(2 * Math.PI * x_axis[i]);
            P_right[i] = 0.5 + 0.5 * Math.Cos(2 * Math.PI * x_axis[i]);
        }

    }
    public unsafe override void Draw()
    {
        ImPlot.SetNextAxesToFit();
        if (ImPlot.BeginPlot("asdf"))
        {
            fixed (double* P_left_ptr = P_left)
            {
                ImPlot.PlotLine("P_left", P_left_ptr, 5);
            }
                        // this fails too:
            //ImPlot.PlotLine("P_right", ref x_axis[0], ref P_right[0], 512, 0);
        }
        ImPlot.EndPlot();
    }
Aberro commented 1 month ago

Figured it... just after creating the post. ImPlot.EndPlot() needs to be called only when ImPlot.BeginPlot() returns true.