C# XNA Visual Studio:“发布"和“发布"之间的区别和“调试"模式? [英] C# XNA Visual Studio: Difference between "release" and "debug" modes?

查看:31
本文介绍了C# XNA Visual Studio:“发布"和“发布"之间的区别和“调试"模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个关于碰撞检测的演示.(其中的一些代码在此处有详细说明.)在调试模式下,它可以工作美好的.在 Release 模式下,它更快,但碰撞检测真的一团糟.物体不会被任何物体反弹,或者似乎受到重力的轻微影响.有些物体爆炸,就好像它们与特殊的爆炸物体发生了碰撞,即使这些物体都不存在.

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.

那么...导致此问题的 Visual Studio 在发布和调试模式之间发生了什么变化?(我使用的是 VS Pro 2008.)

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.

推荐答案

我的超能力并不强,如果不实际调试就很难判断发生了什么.但这是一个猜测.我在这里讨论的问题:

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:

为什么这个浮动-点计算在不同的机器上给出不同的结果?

不仅适用于跨机器",还适用于调试与发布".您的程序的发布版本不仅有可能而且很可能使用比您的调试版本更高精度的数学.如果您在那里有浮点错误,那么完全有可能只是由于运气不好,您只会在更高精度的发布版本中遇到错误,而在低精度调试版本中却没有.

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.

为什么不同?因为在未优化的版本中,C# 编译器经常为临时值生成代码,就好像它们是局部变量一样;然后抖动实际上在堆栈上分配临时局部变量,并将临时值从寄存器写入局部变量.然后,当它需要它们时,它会将它们从临时文件读回寄存器.该过程可能导致高精度寄存器中的值被截断为仅 64 位精度,从而丢失精度位.

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.

在优化版本中,C# 编译器和抖动会更加努力地始终将所有内容保存在寄存器中,因为显然这更快、精度更高,但更难调试.

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.

这篇关于C# XNA Visual Studio:“发布"和“发布"之间的区别和“调试"模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆