Mattsa008 / pybox2d

Automatically exported from code.google.com/p/pybox2d
Other
0 stars 0 forks source link

[pure python] Error in contact generation #52

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. It's an obvious programming error: contacts will generate despite being 
existent already
2. The nested for loops are not handled properly. When an existing contact is 
detected, it just searches for more existing contacts (and does nothing). 
However, it should skip generating a new contact.

*** mark the error lines

def find_new_contacts(self):
        for proxy_a, proxy_b in self.broadphase.update_pairs():
            assert(proxy_a and proxy_b)

            fixture_a = proxy_a.fixture
            fixture_b = proxy_b.fixture

            body_a = fixture_a._body
            body_b = fixture_b._body

            # If the fixtures are on the same body, ignore it
            if body_a == body_b:
                continue

            index_a = proxy_a.child_index
            index_b = proxy_b.child_index

            # Does a contact already exist?
            for contact in body_b._contacts:
                if contact.other_body(body_b) == body_a:
                    continue
                    fa, fb = contact._fixture_a, contact._fixture_b
                    ia, ib = contact._index_a, contact._index_b

                    if fa==fixture_a and fb==fixture_b and ia==index_a and ib == index_b:
                        # A contact already exists
                        continue *** does effectively nothing

                    if fa==fixture_b and fb==fixture_a and ia==index_b and ib == index_a:
                        # A contact already exists
                        continue *** same as above, does nothing

            # Does a joint override collision? Is at least one body dynamic?
            if not body_b._should_collide(body_a):
                continue

            # Check user filtering.
            if self.contact_filter is not None and not self.contact_filter(fixture_a, fixture_b):
                continue

            # Create a contact through the factory.
            c = Contact._create(fixture_a, index_a, fixture_b, index_b)

Original issue reported on code.google.com by ruck.tob...@gmail.com on 29 Sep 2013 at 5:23

GoogleCodeExporter commented 8 years ago
Great find! I appreciate that someone is at least mucking around with the Pure 
Python port, however unpractical it may be. 

Fix should be here: 
https://code.google.com/p/pybox2d/source/diff?spec=svn375&r=375&format=side&path
=/branches/pure_python/pypybox2d/contact_manager.py

Please do let me know if you run into anything further.

Original comment by sir...@gmail.com on 29 Sep 2013 at 5:53

GoogleCodeExporter commented 8 years ago

Original comment by sir...@gmail.com on 1 Oct 2013 at 11:28