Skip to content

Fixed AddConvexPolyFilled and AddPolyLine parameters#345

Open
img02 wants to merge 1 commit into
ImGuiNET:masterfrom
img02:master
Open

Fixed AddConvexPolyFilled and AddPolyLine parameters#345
img02 wants to merge 1 commit into
ImGuiNET:masterfrom
img02:master

Conversation

@img02

@img02 img02 commented Aug 5, 2022

Copy link
Copy Markdown

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

@zaafar

zaafar commented Aug 5, 2022

Copy link
Copy Markdown
Collaborator

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.

@img02

img02 commented Aug 5, 2022

Copy link
Copy Markdown
Author

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.

@zaafar

zaafar commented Aug 5, 2022

Copy link
Copy Markdown
Collaborator

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]);

@gsuberland

Copy link
Copy Markdown

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

@NoahStolk

NoahStolk commented Jun 2, 2023

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants