Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed AddConvexPolyFilled and AddPolyLine parameters #345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

img02
Copy link

@img02 img02 commented Aug 5, 2022

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
Copy link
Collaborator

zaafar commented Aug 5, 2022

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
Copy link
Author

img02 commented Aug 5, 2022

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
Copy link
Collaborator

zaafar commented Aug 5, 2022

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

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

@NoahStolk
Copy link
Contributor

NoahStolk commented Jun 2, 2023

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.

None yet

4 participants