Maximum vertex count Polygon

Hello,

I want to modify the b2_maxPolyVertices to 128 or 256, because I need a polygon with more than 8 vertices.
So I change the b2_maxPolyVertices in b2Settings.h to 128, as explained in the manual.
If I run my application I get an error and the app crash, I don't know why.
Please can somebody help me, this is very important for me!?

Here the error:
Code:
Assertion failed: 0 < size && size <= b2_maxBlockSize, file b2BlockAllocator.cpp, line 104

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I don't have the code in front of me, but I would imagine that means that the size of a polygon shape object is now greater than the block size used by the internal memory management system.

What is the actual maximum number of vertices that you need for your simulation? Is it actually 128? Or is it fewer than that?

It may be that the allocator block size is also configurable (I don't know off the top of my head - you'll have to check the source), but I think the easiest solution would be to set b2_maxPolyVertices to the maximum number of vertices actually needed rather than to an arbitrary value such as 128. If you've chosen that number because you think you'll actually need that many vertices, than I'd recommend setting up your collision geometry differently so that a lower vertex count can be used.
I don't know exactly the number of vertices, but I think I need
more than 100.
Now I change the maximum number to 16,
and the app crashes, but without error message.
There is only the windows error dialog, that the app doesn't work anymore.
Quote:
I don't know exactly the number of vertices, but I think I need
more than 100.

Why do you need so many vertices? That sounds a bit impractical. Are your polygons convex?

Quote:
Now I change the maximum number to 16,
and the app crashes, but without error message.
There is only the windows error dialog, that the app doesn't work anymore.

Are you setting the max to 16 and then creating polygons with more than 16 vertices? If so, that would probably explain the crash.
I have to build a static body with the silhouette of a human.
I think the easiest way for this is a polygon.

No I create no polygons with more than 16 vertices,
only 4 simple boxes, nothing else.
Quote:
I have to build a static body with the silhouette of a human.
I think the easiest way for this is a polygon.

I think you may be overlooking the fact that polygon shapes in Box2D must be convex. The silhouette of a human is, in general, non-convex, so even without the vertex limit, a polygon would still not be the right choice here.

Here are two alternatives to consider:

1. If you're using a version of Box2D that supports 'edge shapes' in one form or another, build the silhouette out of a chain of edges rather than out of a single polygon. (If you're using the current C++ version, 'edge' shapes are simply single polygons with two vertices.)

2. If you don't have edge shapes available, get a hold of a tessellation library (there was one posted here on the forums a while back) and subdivide the silhouette into multiple convex polygons. (This assumes that it's ok for the interior of the shape to be solid.)
Oh yes, you're right, that's a problem.

Your first alternative sounds good, I think my version of Box2D supports edge shapes.

Thanks!
Hello,

I'm still having the problems with the complex objects.
For testing I've a polygon with 125 vertices.
Image

I want to create the silhouette of this polygon as static body in box2d.
First I use edge shapes with a chain of edges, here I have the problem
that at some regions of the silhouette other objects can go through the silhouette
into the person, at other regions not. I know that an edge shape has different
collision setting at the both sides.
I think in this case it's a problem with convex and concave areas.
But in my opinion, the test DynamicEdges of the Testbed has also a
chain of edges with concave areas, but here no objects can go into the object.

After this disenchantment, I use a triangulation algorithm to split the polygon in triangles.
(I use this algorithm: http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml)
This algorithm works fine,but if I tried to create the triangles in box2d, I get the
following error
Code:
Assertion failed: d.x >= 0.0f, file b2PolygonShape.cpp, line 224


I read that a shape in box2d must have a minimum size, I think hte triangles are to small.

I'm really despaired because I have to make this work and I have no idea what to do.
Please can somebody help me?
What version of Box2D are you using? I haven't used edge chains myself, so I can't really say why they're not working for you. Are you sure that the edges are all oriented correctly and consistently? Have you tried making simpler shapes out of edges to see if you get the same behavior?

In any case, I'd probably stick with triangulation/polygonization myself. Keep in mind that not all polygonization algorithms are the same, and some are more prone to generating small and/or narrow polygons/triangles than others.

In particular, there are methods (such as Delaunay triangulation) that can be tweaked so as to maximize triangle areas where possible - this is probably what you want. I don't know what algorithm the flipcode article describes, but I know there was code posted to these forums fairly recently that implemented (I think) Delaunay triangulation. The project is on Google code - if you search the forums for, say 'triangulation' or 'tessellation', you should be able to find the thread.
I use the version 2.0.2. I think the edges are all oriented correctly,
but I don't test if simpler shapes have the same behaviour, but I'm going
to test this in the next days.

I think that I found the code, the project is called poly2tri.
I will test this library and also continue searchig of other libraries.

Original thread: https://box2d.org/forum/viewtopic.php?t=4678