Only 1 contact updated on setFriction: plus Solution

Bugs will be moved here once resolved.

Post » Fri Feb 20, 2015 12:49 am

I posted this in the closed bug forum : https://www.scirra.com/forum/friction-bug-contacts-can-be-updated_t124639 , but I remembered that you don't necessarily check there. So I am putting this here.

b2body.GetContactList(); isn't meant to return a list but rather a single b2ContactEdge object. you can get the next object in the list (managed by the body) by using .get_next(); However, there is a bug in ams.js that causes .get_next() to always return an object, even at the end of the list. So, you have to use a workaround; Box2d.getPointer( B2ContactEdge ) !==0;

The following code resets friction across all contacts, and worked fine with the tests I ran.

In SetFriction:

for (var contactEdge = this.body.GetContactList();
Box2D.getPointer(contactEdge) !==0;
contactEdge = contactEdge.get_next())

{
var contact = contactEdge.get_contact();
if (contact)
contact.ResetFriction();
}

Sorry for the double post if you read the other. I just wanted to make sure you got this! It took way to long to figure out and I didn't want anyone repeating the work if they didn't have to. ... and sorry for not following proper bug posting. I didn't think it was needed here, as it is a known bug.

relevant post: https://github.com/kripken/box2d.js/issues/17
Image
B
32
S
11
G
2
Posts: 563
Reputation: 5,106

Post » Mon Feb 23, 2015 1:29 pm

OK, updated for the next build. I'm not clear on how far get_next() will go though - will it continue to iterate through all contacts in the world? That would impact performance. But added it anyway so it works correctly.
Scirra Founder
B
386
S
229
G
87
Posts: 24,207
Reputation: 191,582

Post » Mon Feb 23, 2015 6:12 pm

@Ashley - As far as I can tell, contactedge.get_next() is only supposed to go through the contacts connected to the body in question. if you use contact.next(), that will go through all contacts in the world. But without using box2d.getpointer() the loop will run forever and contactEdge.get_next() keeps returning empty b2 contact edges.

I edited the code to count how many times the loop is running... It runs only as many times as there are physics contacts affected the body. So it looks like it is running as it should.
Image
B
32
S
11
G
2
Posts: 563
Reputation: 5,106

Post » Mon Feb 23, 2015 6:32 pm

OK, good to know - thanks.
Scirra Founder
B
386
S
229
G
87
Posts: 24,207
Reputation: 191,582


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests