ivansafrin/Polycode — Issue #73: Misbehavior if addCollisionChild and addPhysicsChild both called
Author: mcclure
Created: 2011-12-23 18:06:23+00:00
State: open

Last night was doing some stuff with Physics2D. I called "addCollisionChild" and "addPhysicsChild" on the same object (on purpose-- I mistakenly thought this was what I was supposed to do). I saw the following misbehavior:

- On the first frame of physics simulation, I got a new collision event reporting the object had collided with itself.
- On every "real" collision with the object, I saw four collision events rather than one

I then inspected the examples and saw that if you call addPhysicsChild you do not need to call addCollisionChild. Okay, problem solved. But

I would suggest considering one or all of the following:

- If both addCollisionChild and addPhysicsChild are called on the same object, the redundant call is discarded (or potentially a collision child is upgraded to a physicschild)
- The documentation should be altered to unambiguously state that addPhysicsChild implies addCollisionChild (and you therefore do not need to call both)
http://polycode.org/docs/physics2d/class_polycode_1_1_physics_screen.html#a2ffc2231336057670450be2ba1a48660

It might also be worth it eventually to have a "physics debug warning" mode, where if the programmer does something nonsensical (like add an object twice to the space, or create a degenerate polygon, or a polygon with NaN points) a warning will be printed to stderr.