Hi,
I think there are two bugs in b2Fixture::SetSensor, but maybe someone can clarify just in case I'm missing something. Or maybe this might help someone!
The portion of that function's code in question is:
First, if edge is not null, this will go into an infinite loop. I fixed it by adding
at the end of the loop.
Second, if you call SetSensor(false) and it is currently colliding with something that is a sensor, then it will make the contact not a sensor even though it should still be a sensor (it is colliding with a sensor). I fixed this by adding:
so the final code is:
I'm using code from the google svn repository and it is up to date as of this date.
-j
I think there are two bugs in b2Fixture::SetSensor, but maybe someone can clarify just in case I'm missing something. Or maybe this might help someone!
The portion of that function's code in question is:
Code:
// Flag associated contacts for filtering.
b2ContactEdge* edge = m_body->GetContactList();
while (edge)
{
b2Contact* contact = edge->contact;
b2Fixture* fixtureA = contact->GetFixtureA();
b2Fixture* fixtureB = contact->GetFixtureB();
if (fixtureA == this || fixtureB == this)
{
contact->SetAsSensor(m_isSensor);
}
}
b2ContactEdge* edge = m_body->GetContactList();
while (edge)
{
b2Contact* contact = edge->contact;
b2Fixture* fixtureA = contact->GetFixtureA();
b2Fixture* fixtureB = contact->GetFixtureB();
if (fixtureA == this || fixtureB == this)
{
contact->SetAsSensor(m_isSensor);
}
}
First, if edge is not null, this will go into an infinite loop. I fixed it by adding
Code:
edge=edge->next;
at the end of the loop.
Second, if you call SetSensor(false) and it is currently colliding with something that is a sensor, then it will make the contact not a sensor even though it should still be a sensor (it is colliding with a sensor). I fixed this by adding:
Code:
contact->SetAsSensor(fixtureA->IsSensor()||fixtureB->IsSensor());
so the final code is:
Code:
// Flag associated contacts for filtering.
b2ContactEdge* edge = m_body->GetContactList();
while (edge)
{
b2Contact* contact = edge->contact;
b2Fixture* fixtureA = contact->GetFixtureA();
b2Fixture* fixtureB = contact->GetFixtureB();
if (fixtureA == this || fixtureB == this)
{
contact->SetAsSensor(fixtureA->IsSensor()||fixtureB->IsSensor());
}
edge=edge->next;
}
b2ContactEdge* edge = m_body->GetContactList();
while (edge)
{
b2Contact* contact = edge->contact;
b2Fixture* fixtureA = contact->GetFixtureA();
b2Fixture* fixtureB = contact->GetFixtureB();
if (fixtureA == this || fixtureB == this)
{
contact->SetAsSensor(fixtureA->IsSensor()||fixtureB->IsSensor());
}
edge=edge->next;
}
I'm using code from the google svn repository and it is up to date as of this date.
-j