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

ERROR: set_data: Condition ' len % 2 ' is true #19353

Open
Tracked by #45334
marsmoon opened this issue Jun 4, 2018 · 5 comments
Open
Tracked by #45334

ERROR: set_data: Condition ' len % 2 ' is true #19353

marsmoon opened this issue Jun 4, 2018 · 5 comments

Comments

@marsmoon
Copy link

marsmoon commented Jun 4, 2018

commit hash: 8684b63

I'm getting a lot of those errors when dynamically changing the array of segments in ConcavePolygonShape2D (adding points). Collisions on some of the segments don't work. Errors are from servers/physics_2d/shape_2d_sw.cpp:910.

What does this error mean?

@PJB3005
Copy link
Contributor

PJB3005 commented Jun 5, 2018

Seems like ConcavePolygonShape2DSW requires the data passed in to have an even amount of points. len % 2 is true for odd numbers.

@vnen
Copy link
Member

vnen commented Jun 5, 2018

You can only add segments to ConcavePolygonShape2D, not points, so they need to be pairs of points to define the segments.

@marsmoon
Copy link
Author

marsmoon commented Jun 5, 2018

Thanks for the answer, but why can't it create a segment from for example 3 points?

@vnen
Copy link
Member

vnen commented Jun 5, 2018

Well, 3 points might not be in the same line, if you need it you can add the middle point twice (and if they are in the same line, you don't need the middle point anyway).

Internally it stores everything in a contiguous array of points and it assumes it contains pair of points to define segments. This is done for performance reasons.

@Xrayez
Copy link
Contributor

Xrayez commented Jun 30, 2020

Internally it stores everything in a contiguous array of points and it assumes it contains pair of points to define segments. This is done for performance reasons.

I think the performance impact is negligible, at least in terms of that the collisions against concave shapes are slower already compared to using convex shapes (for rigid bodies at least). I mean, isn't it possible to use segments internally, defining a polygon via points is more intuitive in contrast to segments. Also, it may be difficult to edit concave shapes in the editor in the future (if not using CollisionPolygon2D): #21394. I prefer correctness over performance in this case.

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

Successfully merging a pull request may close this issue.

5 participants