ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

Fixed AddConvexPolyFilled and AddPolyLine parameters

Open img02 opened this issue 2 years ago • 5 comments

Changed params from ref Vector2 to array Vector2[]

Fixed result: convexpolyfilled and polyline png

previous result: (could only pass single vec2) convexpoly and polyline - Current

img02 avatar Aug 05 '22 01:08 img02

as the name suggests Generated/ImDrawList.gen.cs these are generated files. they would be overwritten automatically next time someone generate them again. no point in modifying them.

zaafar avatar Aug 05 '22 05:08 zaafar

Oh, I don't really know how that works, but wouldn't this at least fix it temporarily? either way, currently those 2 functions don't work.

img02 avatar Aug 05 '22 07:08 img02

yeah, same here, no idea. I would suggest reading/understanding/debugging this project: https://github.com/mellinoe/ImGui.NET/tree/master/src/CodeGenerator

As a workaround do the following:

// assuming this is a function where you want to pass the array
private static void kkk(ref Vector2 k) { }
// this is how you pass the array.
Vector2[] k = new Vector2[20];
kkk(ref k[0]);

zaafar avatar Aug 05 '22 20:08 zaafar

@zaafar Is that safe to do? i.e. is .NET not free to arbitrarily allocate the array in non-contiguous memory space?

gsuberland avatar Aug 28 '22 02:08 gsuberland

I know this is an old PR, but I'd just like to state that even if we were to change the code generator, I'm pretty sure this is by design and does not need fixing / should not be changed. You're expected to invoke these methods as follows:

private static readonly Vector2[] _points =
{
    new(300, 300),
    new(600, 600),
    new(300, 600),
    new(300, 300),
};

void Render()
{
    ...
    drawList.AddPolyline(ref _points[0], points.Length, ...);
}

Works perfectly fine for me. I don't think it's a workaround.

@zaafar Is that safe to do? i.e. is .NET not free to arbitrarily allocate the array in non-contiguous memory space?

@gsuberland I think it should be safe? But to be sure you could also pin the memory like this to prevent that from happening (requires unsafe):

fixed (Vector2* p = _points)
    drawList.AddPolyline(ref p[0], _points.Length, ...);

Maybe it should be made clear somewhere how to properly use these methods though.

NoahStolk avatar Jun 02 '23 13:06 NoahStolk