Greetings,
This is the code currently I see in world:DestroyBody (Box2d Version: Major: 2, Minor 1, Revision: 0):
The problem is that I am implementing a SayGoodbye method to remove my userdata when ALL the fixtures have been destroyed... but for each SayGoodbye call I get for the same body (when a body has more than one fixture) the fixturelist remains the same (is not always accurate). Shouldn't the fixture list be updated after each SayGoodbye call so the receivers of the next SayGoodbye call (for the next fixture in same body) can be assured that the fixture list is accurate ?
Basically what is needed is to move the body's fixturelist ptr past the fixture that has been removed and to decrement the fixturecount. As it stands now, there is no guarantee the fixture list is accurate for implementors of the SayGoodbye method.
Here is one possible solution:
Second question (which is more of a feature request: Assuming the above gets implemented in Box2d, could we allow readonly access to m_fixtureCount? There are several cases where knowing the number of fixtures of a body is helpful and it seems sort of inefficient to count them over and over again when that information is already known to the body...it is just currently not visible.
As I said, I *think* this is a bug, but not knowing the internals of box2d I could be wrong.
Any help or info would be appreciated.
Regards,
Q
This is the code currently I see in world:DestroyBody (Box2d Version: Major: 2, Minor 1, Revision: 0):
Code:
[...etc...]
// Delete the attached fixtures. This destroys broad-phase proxies.
b2Fixture* f = b->m_fixtureList;
while (f)
{
b2Fixture* f0 = f;
f = f->m_next;
if (m_destructionListener)
{
m_destructionListener->SayGoodbye(f0);
}
f0->DestroyProxy(&m_contactManager.m_broadPhase);
f0->Destroy(&m_blockAllocator);
f0->~b2Fixture();
m_blockAllocator.Free(f0, sizeof(b2Fixture));
}
b->m_fixtureList = NULL;
b->m_fixtureCount = 0;
[....etc ...]
// Delete the attached fixtures. This destroys broad-phase proxies.
b2Fixture* f = b->m_fixtureList;
while (f)
{
b2Fixture* f0 = f;
f = f->m_next;
if (m_destructionListener)
{
m_destructionListener->SayGoodbye(f0);
}
f0->DestroyProxy(&m_contactManager.m_broadPhase);
f0->Destroy(&m_blockAllocator);
f0->~b2Fixture();
m_blockAllocator.Free(f0, sizeof(b2Fixture));
}
b->m_fixtureList = NULL;
b->m_fixtureCount = 0;
[....etc ...]
The problem is that I am implementing a SayGoodbye method to remove my userdata when ALL the fixtures have been destroyed... but for each SayGoodbye call I get for the same body (when a body has more than one fixture) the fixturelist remains the same (is not always accurate). Shouldn't the fixture list be updated after each SayGoodbye call so the receivers of the next SayGoodbye call (for the next fixture in same body) can be assured that the fixture list is accurate ?
Basically what is needed is to move the body's fixturelist ptr past the fixture that has been removed and to decrement the fixturecount. As it stands now, there is no guarantee the fixture list is accurate for implementors of the SayGoodbye method.
Here is one possible solution:
Code:
// Delete the attached fixtures. This destroys broad-phase proxies.
b2Fixture* f = b->m_fixtureList;
while (f)
{
b2Fixture* f0 = f;
f = f->m_next;
if (m_destructionListener)
{
m_destructionListener->SayGoodbye(f0);
}
f0->DestroyProxy(&m_contactManager.m_broadPhase);
f0->Destroy(&m_blockAllocator);
f0->~b2Fixture();
m_blockAllocator.Free(f0, sizeof(b2Fixture));
b->m_fixtureList = f; // <-------------- ADDED THIS
b->m_fixtureCount--; // <-------------- ADDED THIS
}
b->m_fixtureList = NULL; // Technically this line would no longer be needed
b->m_fixtureCount = 0; // Technically this line would no longer be needed
b2Fixture* f = b->m_fixtureList;
while (f)
{
b2Fixture* f0 = f;
f = f->m_next;
if (m_destructionListener)
{
m_destructionListener->SayGoodbye(f0);
}
f0->DestroyProxy(&m_contactManager.m_broadPhase);
f0->Destroy(&m_blockAllocator);
f0->~b2Fixture();
m_blockAllocator.Free(f0, sizeof(b2Fixture));
b->m_fixtureList = f; // <-------------- ADDED THIS
b->m_fixtureCount--; // <-------------- ADDED THIS
}
b->m_fixtureList = NULL; // Technically this line would no longer be needed
b->m_fixtureCount = 0; // Technically this line would no longer be needed
Second question (which is more of a feature request: Assuming the above gets implemented in Box2d, could we allow readonly access to m_fixtureCount? There are several cases where knowing the number of fixtures of a body is helpful and it seems sort of inefficient to count them over and over again when that information is already known to the body...it is just currently not visible.
As I said, I *think* this is a bug, but not knowing the internals of box2d I could be wrong.
Any help or info would be appreciated.
Regards,
Q