Newly created object falling through the floor

Hi,
I've got a problem where when creating and positioning a new object,the object falls through the floor.

I have been playing with the location that the new object and it appears that if the object is created entirely outside of the bounding box of the floor.

I've tried setting allowSleep to false, setBullet to true. These have no effect on what happens.

Here's an example: http://www.youtube.com/watch?v=0-r0-qdezvY

In the above demo, if I set the position when crouching to 100 above the floor this doesn't happen.

When the player crouches, his object is replaced with a shorter object. As you can see the new object is created inside of the bounding box of the slightly angled floor (ignore the floor graphics. They're wrong., the box is the physics object). This is obviously not a problem when the floor is flat, because the bounding box is the same as the shape, and thus the new shape is always created outside of it.

Why does the object not collide if their bounding boxes initially intersect?
Ok, not sure why this is necessary but here's what I had to do to fix the problem:

Code:
for (Shape s = m_body.getShapeList(); s != null; s = s.m_next)
  m_world.refilter(s);


That fixed the issue completely... but why is the shape not filtered to begin with?
Quote:
if I set the position when crouching to 100 above the floor this doesn't happen.


Just out of curiosity, what scale are you using in this simulation? If your objects are enormous, this could cause problems. The Box2D engine is optimized for SI units (or MKS) with, if I recall correctly recommended shape sizes being larger than a rock and smaller than a house.
64px at the simulation's native resolution (1920x1080) equal 1 unit in the physics engine. That way the player is about 1.9 units tall. Everything in this simulation is within approximately power of 10 of one unit.
Ok, then this is likely causing you significant problems. You might want to consider rescaling as the collision detection system is not "tuned" to handle such large numbers. If a man is almost 2 units tall and Box2D is optimized for meters, then effectively (to the engine) your man is 128 meters tall when he should be more like 2 meters tall (for a tall person, like me). I would recommend addressing this issue before you go any further, otherwise you are likely to encounter more issues like this sooner or later.
No, I have it configured to the reverse. 64px is 1 unit in JBox2d. Sorry if I didn't make that clear.
My apologies, I misread. This scaling sounds reasonable then. Off the top of my head, I can't think of a reason you would need to call a contact refiltering function. Can you post some code of how you are creating a body, maybe creating your World as well?

It sounds like it would have to be something strange with creating bodies or shapes (vertex coordinate issues).

Edit:
Ok, I just reread your original post. When you replace the standing man body with the crouching body, do you recreate the body each time or just move them around manually? Not saying that you would want to newly create bodies each time as it would be very inefficient. But if you are just moving by setting the position, then I think the engine will need to have contacts refiltered or updated in some way. Basically, if you move the crouched body from far off-screen to your man's position on the ground then the crouching body has skipped the process of being considered for broad phase detection which is where contacts are formed. Refiltering or updating contacts will force the engine to "take another look." This is also the case if you change a shape's property midstream, like restitution or friction. Also something to consider, if you move the hidden body outside the world AABB, then the body will be marked as frozen which will not be able to move or collide until it is unfrozen, but (if I recall correctly) unfreezing a body is a slightly more involved process than simply removing the frozen flag.
Hmm, actually I think that explains it. The object is not in an area that should be considered for collision, then I artificially move it there and poof, we have no collision. I'm not exactly sure why it doesn't collide in the 2nd step, once gravity and stuff are applied (since it collides with the next object below the one it initially falls through, just never the one it starts inside the bounding box with), but I'm happy with a solution that seems to mostly make sense.

Original thread: https://box2d.org/forum/viewtopic.php?t=5507