c++ - Box2D crash in b2BlockAllocator.cpp -


i have begun using box2d c++ , visual studio 2015 , experiencing strange bug in access violation caused b2blockallocator.cpp @ line 155. appears array assigned sort of b2block linked list structure, next value null. triggers access violation.

if (m_freelists[index]) {     b2block* block = m_freelists[index];     m_freelists[index] = block->next; // <- error occurs here.     return block; } else {... 

but here's what's weird. have been developing game library personal use, , following code used instantiate b2body in physicsobject class in game library:

void physicsobject::oncreate() {     /**/     b2bodydef bodydef;     bodydef.type = m_bodytype;     bodydef.position.set((float)(m_x + m_width / 2) / (float)m_plevel->gettilesize(), (float)(m_y + m_height / 2) / (float)m_plevel->gettilesize());     m_pbody = m_plevel->getworld().createbody(&bodydef);      b2polygonshape shape;     shape.setasbox((float)m_width / (float)m_plevel->gettilesize() * 0.5f, (float)m_height / (float)m_plevel->gettilesize() * 0.5f);      b2fixturedef fixturedef;     fixturedef.shape = &shape;     fixturedef.density = 1.0f;     fixturedef.friction = 0.3f;     m_pbody->createfixture(&fixturedef); // <- call last executed before error.     /**/ } 

this in game library, visual studio dll project, , works fine. however, when move exact code class derives physicsobject in test project references game library, crash occurs. allocating each object heap doesn't make difference either, box2d documentation states objects passed not keep references. if helps, box2d statically linked library. both test project , game library have exact same dependencies , in same configuration. have idea why might happening? appreciated.

update:

i have discovered causing crash, i'm not sure how go fixing it. issue box2d's block allocator becoming corrupt somehow after b2body being created world. list of free chunks looks before allocation:

before allocation

and after b2body created:

after allocation

as can see, there corrupted memory in chunk list. know why happening? statically linking project solve this?

the issue experiencing had corrupted memory occurred between transfer code in dll code in executable. while i'm not sure why was, think might have had dll hell. solution make game library static library instead of dynamic one. compiled code directly executable , no corrupted memory caused transition occur.


Comments