It's been a long ride

Haha, you gave me a test.

Continuous collision certainly seems disastrous!

I notice that holding 'c' makes Confined Test angry.
haha yes continuous collisions isn't working yet for polygons-on-polygon, but it works for the circles in the confined test. Yeah if you turn all the drawing on it goes crazy!

Also, you may have noticed sometimes user input causes lots of exceptions. this is because I haven't made the input thread-safe yet.
The Flash forum has more posts in it than even the General one does. But we are still on the side of justice. Do not lose heart
Huh, Varying Friction seems to go crazy in a different way each time I run it. The engine is still deterministic right? I guess it's probably just a caching problem or something.
Re: determinism: I just did some tests, and no, the Java port of the engine is not deterministic, even on the same computer, even in the stable 2.0.x versions. Apparently the AS3 version also suffers from this problem, which doesn't surprise me - I've written physics in AS3 before manually, and was shocked to discover that determinism doesn't hold between different runs.

Every action within the engine should be deterministic, but alas, the sum of the parts doesn't work out that way, many situations run differently each time they're run, even though every call is the same (and no randomization is involved).

IMO, what's happening is that the JVM is possibly generating very slightly different code when it compiles methods, and it's likely allowing optimizations that can slightly alter FPU results (changing orders of operations, using different amounts of internal precision, changing what things are held in registers as opposed to loaded back to memory, etc.).

We might be able to thwart this by forcing strictfp mode, that's supposed to force consistency (actually, it might even work to force consistency between all processor/OS types, I'm not sure), but I haven't tried it, and it would take a bit of work to add the modifier to every class manually (it would also slow down the engine quite a bit, I think). If someone wants to give it a shot, you just need to tag each class file with strictfp: http://en.wikipedia.org/wiki/Strictfp. Someone could probably write a script to do it fairly easily, and that might be worth posting here if it does make things consistent.
My mind is blown
MJW wrote:
My mind is blown

I know what you mean, I kind of couldn't believe this when I discovered it, it was only when I ran some tests with some very complicated structures that became somewhat unstable that I found it blew up in a different way each time I ran it.

I'm going to try to put together a minimal bit of example code (not using JBox2d) that demonstrates this non-determinism, I'll let you know when I get something.
Could inconsistent JIT optimization be the culprit? Twenty minutes' Googling was unable to produce for me any better answer than... maybe. It does sound like the strictfp keyword could indeed somewhat easily be used to quash the problem, anyway... though in that case one would need two whole versions of one's program. 🙁

I don't care deeply about determinism, myself. But I'd prefer to have it.
Toucansam isn't dead is he?
MJW wrote:
Could inconsistent JIT optimization be the culprit? Twenty minutes' Googling was unable to produce for me any better answer than... maybe.

Possibly, but I'm not sure. The weird thing is, the inconsistencies persist even once JIT compilations stop (you can watch them with -XX:+PrintCompilation), so whatever non-determinism is happening, it's happening within the same compiled code, at least I think it is (unless the JVM is switching between compiled versions of code? I dunno...). Also have not been able to find much info on this online.

Quote:
It does sound like the strictfp keyword could indeed somewhat easily be used to quash the problem, anyway... though in that case one would need two whole versions of one's program. 🙁

Apparently this is the case: http://zetsgames.com/deterministic-physics/ seems to have tried that, and it worked.

Sucks that strictfp has to be added as a modifier, there's no way to turn it on and off for a whole codebase with a single flag, at least without adding a preprocessing step.

However, at least this tells us that it's not something wrong with the way the engine is coded, it's actually just an issue with the way floating point is handled in Java. And if strictfp works, that should actually give cross-platform consistency in Java, which is vastly more difficult to obtain in any other language, including C++. This could actually be the "killer feature" of the Java port if we were to add strictfp, though I'd want to measure the performance hit before going for it...

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