ImGui.NET
ImGui.NET copied to clipboard
Fixed AddConvexPolyFilled and AddPolyLine parameters
Changed params from
ref Vector2
to array
Vector2[]
Fixed result:
previous result: (could only pass single vec2)
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.
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.
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 Is that safe to do? i.e. is .NET not free to arbitrarily allocate the array in non-contiguous memory space?
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.