Dynamically making objects static (Round 2)

It's been a while but I'm revisiting an old feature and running into new problems. See the last thread for some background.

I've basically got a platformer game where I occasionally pause and unpause the gameworld.

While the gameworld is unpaused, everything works great. If I pause then unpause, it works great. If I pause the game and walk around on now-frozen dynamic items, it works great.

However, if my player character touches any now-frozen object that has a joint on it, all the connected world items just disappear with X and Y coordinates registering as 0,0. They aren't actually at 0,0 - they trigger the boundaryListener, so apparantly they are leaving the world altogether or having their x and y values turning to null.

I've turned off warm starting, I've turned off my own contact listener and boundary listener - same results. I'm using a vesrion from about 1.5 weeks ago from the SVN. I've run the bug through a variety of scenarios and it's fairly consistent - only if the player touches a static object with a joint does the error occur.

Any idea why this would occur, or where I could start looking to make it work? I'm at a complete loss.

I have an example level done up for ease of display: http://www.protonaut.net/dev/21.swf?levelId=362
The level is rigged so all you have to do is watch, then hit "spacebar" to pause the level. Using WASD you can jump onto the stack of rods and you will see the error.

"R" resets the game, then try the same thing except collect the ball on the right before pressing space. no error!
it looks like the objects that are jointed together have collisions, and are being held together while being jointed, when the joint is popped the objects all bounce apart. Do you have collide connected set to true? Also, are you setting the linear and angular velocities to 0 for your static objects? ( I don't remember if you said you were in the other thread )

Only thing I can think is that when you touch the static objects, they have an accumulated force that is launching you off and it is definitely tied to that joint.
I just stacked the objects up to show the behaviour - here's a level where there is no such collision, and the bug remains:

http://www.protonaut.net/dev/21.swf?levelId=363

Just hit spacebar and hop onto the brown platform to the right. When the objects are "static" and you touch it, it will dissapear in a puff of smoke (without destroying the joint).

My first instinct is to say there's a problem creating joints on static objects, but it worked in older versions...
I am by no means on expert on this so take my opinion with a grain of salt... with that said, I wonder if it has anything to do with how the engine is caching contacts and interactions... it might not correctly identify that the joint is now attached to a static object. Have you tried destroying and recreating the joint when it goes static?
For that matter, you actually don't need the joint when its static if nothing is moving... you could just temporarily destroy the joint and recreate it when the world comes back to dynamic.
Hmm. Have you tried putting a joint on two ordinary static bodies, and then moving one (so the joint doesn't fit). It's possible that Box2D just doesn't check for this circumstance, and always blows up. Some checks to IsStatic inside Solve should fix it, if that's the case. Or it that's too much work for you, just comment out all solving of joints when your world is frozen, assuming the player doesn't use any.
If I remove and recreate the joints it seems to work fine - but I would rather fix the bug while I'm at it. 🙂 I guess that just goes to show that it is indeed a problem with the joints.

Further experimentation shows that joints between static and non-static objects are fine as well - the only time this problem crops up is when the joint exists between two static objects. Oddly enough, the last stable release version this worked fine - so it must have been a change somewhat recently (I am currently using the latest SVN version).

I don't believe it has to do with stored/current velocities/momentum, as I generate my worlds with all the items set to Sleep, and I can freeze them right off the bat (where theoretically all their values are zero anyhow).

I slapped a line of code into b2RevoluteJoint.as, line 493, for the function SolvePositionConstraints. Basically, if body1 and body2 IsStatic, then return false and don't execute the code. This solved the problem!

I'm happy to leave that line of code in there, but I'm not sure if there may be any far-reaching unintended consequences of this. For a proper fix I'd imagine this type of code would have to be inserted into every joint type - and maybe it should be returning TRUE, not FALSE when frozen? It's a complex function that I can't begin to decipher.

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