Is Box2d still deterministic when compiled with optimization?
I've found that the physics behaves slightly differently when compiled with -O2 in gcc, enough to cause problems in my game.
If it is not, it is a bug in the compiler or Box2D.
Just to be clear, you mean it behaves differently on consecutive runs of the same -O2 compiled program with the same input?
If you mean it runs differently between -O2 and non-O2 with the same input, that is to be expected.
Why is it to be expected? Optimization is not supposed to change the behavior of a program.
Ug, I just realized that it's even worse than I thought. The behavior changes when I altered a completely unrelated part of the program and recompiled, even though I used the same compiler options.
Why does Intel have to make things so difficult?
When working on various floating point issues with a Lisp compiler vendor, the compiler vendor and myself were surprised to discover how much state appears to remain on the fpu. Even what you ran before you ran your program could influence the output. If you are trying to replay a simulation that needs to appear exactly the same way each time, sorry. You'll need to do a snapshot/syncing method, much like the techniques that are applied towards the general problem of networking latency and packet loss.
Even if I wanted to, it'd be pretty much impossible to do a snapshot. Not to mention that the storage requirements would be ridiculous.