godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.99k stars 21.16k forks source link

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

Open marsmoon opened 6 years ago

marsmoon commented 6 years ago

commit hash: 8684b631182dffebba27bdf538129818321d0d7d

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 commented 6 years ago

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

vnen commented 6 years ago

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

marsmoon commented 6 years ago

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

vnen commented 6 years ago

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 commented 4 years ago

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.