Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

C# XNA Visual Studio: Difference between "release" and "debug" modes?

I'm working on a demo about collision detection. (Some of the code for this is detailed here.) In Debug mode, it works fine. In Release mode, it's faster, but the collision detection is REALLY messed up. Objects to bounce off nothing, or seem be oddly lightly effected by gravity. Some objects explode, as if they have collided with the special explosive objects, even though none of those objects exist.

So... what does Visual Studio change between Release and Debug mode that causes this problem? (I'm using VS Pro 2008.)

Mysteriously, Release mode had been working for plenty of development. It just recently stopped.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My psychic powers are not great, and it is hard to tell what is going on without actually debugging it. But here's a guess. The issue I discuss here:

Why does this floating-point calculation give different results on different machines?

applies not just to "cross machine" but also to "debug vs release". It is not only possible but likely that the release version of your program is using higher precision math than your debug version. If you have floating point bugs in there then it is entirely possible that just by sheer bad luck you are hitting the bugs only in the higher-precision release version and not in the lower-precision debug version.

Why the difference? Because in the unoptimized version the C# compiler frequently generates code for temporary values as though they were local variables; the jitter then actually allocates temporary locals on the stack, and writes the temporary values from the registers to the locals. Then when it needs them, it reads them back into registers from the temporaries. That journey can cause the value that was in the high-precision register to be truncated to mere 64 bit precision, losing bits of precision.

In the optimized version the C# compiler and the jitter work harder to keep everything in registers all the time, because obviously that is faster and higher precision, though harder to debug.

Good luck. Bugs that only repro in release mode are a total pain.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...