LoopShape / BlockAllocator crash + advice needed.

I need to create some polygons with large numbers of vertices (potentially hundreds - tracing the edges of objects provided by another library). Instead of of upping the maximum number of vertices allowed in b2Settings.h, I thought I'd see what LoopShape could do.

I can create a loop with around 20 points, without a problem. When I tried to create one with 25, I get the following assertion error.

Quote:
Assertion failed: 0 < size && size <= b2_maxBlockSize, file C:\Box2D\Common\b2BlockAllocator.cpp, line 104


I managed to get around it by adding larger block sizes to the allocator, but I don't think this is a good solution.

This is pretty much the code I am using just for testing.

Code:
b2BodyDef bd;
bd.position.Set(0.0f, 0.0f);
m_body = m_world->CreateBody(&bd);

int numVerts = vertices.size();
m_vertices = new b2Vec2[numVerts];

for(int i=0; i<numVerts; i++) {
    m_vertices[i].Set(vertices[i].x/BOX2D_RATIO, vertices[i].y/BOX2D_RATIO);
}

b2LoopShape loop;
loop.m_vertices = m_vertices;
loop.m_count = numVerts;

b2FixtureDef fd;
fd.shape = &loop;
fd.density = 0.0f;
fd.restitution = 0.0f;
fd.friction = 0.0f;

m_body->CreateFixture(&fd);


So, am I doing something horribly wrong? Is there a better solution for what I want to do? (Should I just increase b2_maxPolygonVertices?)

Thanks.
There is already an issue on this: http://code.google.com/p/box2d/issues/detail?id=150

I plan to use b2Alloc for loop shape vertices rather than the small object allocator.
Thanks, I'll keep an eye on the SVN for that then, and use my kludge fix for now 🙂
I have made the following changes in b2Fixture.cpp and .

If it's horrible, I apologise, about a week ago I knew enough c++ to write a main loop with a cout in it. Feel free to correct my syntactic aberrations 🙂

In Fixture Create, condition around the allocator at the top:
Code:
   if (def->shape->m_type == b2Shape::e_loop) {
        m_proxies = (b2FixtureProxy*)b2Alloc(childCount * sizeof(b2FixtureProxy));
   }
   else {
        m_proxies = (b2FixtureProxy*)allocator->Allocate(childCount * sizeof(b2FixtureProxy));
   }


In Fixture Destroy, condition around the original free + loop routine change:
Code:
   if (m_shape->m_type == b2Shape::e_loop) {
       b2Free(m_proxies);
   }
    else {
        allocator->Free(m_proxies, childCount * sizeof(b2FixtureProxy));
   }

...

   case b2Shape::e_loop:
      {
         b2LoopShape* s = (b2LoopShape*)m_shape;
         b2Free(s->m_vertices);

...


b2LoopShape Clone:
Code:
...
   *clone = *this;
   clone->m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
...


This fixes my block allocator issues, but I don't know enough about the inner workings of Box2d to know if I am overlooking something and introducing lovely memory leaks etc.

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