作者tonit (tonit)
站内Programming
标题[问题] Release Mode and Debug Mode
时间Sun Apr 13 12:50:01 2008
各位板友好
我遇到一个问题如下:
我正在做图学作业 Photon Mapping
用的编译器是 VC 2005
其中 Debug Mode 的结果是正确
但是 Release Mode 的结果是错误的
我一定得用 Release mode来执行否则我想要画完整一点的图就会画不完
经过追踪
我是在去 kd-tree 拿取 Photon 资料的时候出错
错误程式码节录如下
void PhotonMap :: locate_photons(
NearestPhotons *const np,
const int index ) const
//******************************************
{
const Photon *p = &photons[index];
float dist1;
if (index<half_stored_photons) {
dist1 = np->pos[ p->plane ] - p->pos[ p->plane ]; // p 就出错了
//******************************************
也就是说 指标 p->plane 指出来的结果
在 Release 和 Debug 是不一样的
Release 指到的根本是个乱数 (我用 Release Mode debuger 去看的结果)
我毫无头绪为什麽会发生这样的错误
请问我可以用什麽样的方法来Debug呢?
以下节录 PhotonMap Construtor
//******************************************
PhotonMap :: PhotonMap( const int max_phot )
//************************************************
{
stored_photons = 0;
prev_scale = 1;
max_photons = max_phot;
photons = (Photon*)malloc( sizeof( Photon ) * ( max_photons+1 ) );
//Photon z[sizeof(Photon)*300+1];
//photons = z;
if (photons == NULL) {
fprintf(stderr,"Out of memory initializing photon map\n");
exit(-1);
}
}
//***************************************************
//******************************************
谢谢各位的耐心看完
有任何意见都欢迎回覆
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 130.126.76.76
1F:推 godfat:检查看看 p->plane 有没有正确初始化? 220.135.28.18 04/13 13:37
2F:推 hungche:试试看使用volatile对这个变数不做最佳化 219.84.124.89 04/13 14:08
3F:→ WPC001:先把p->plane改成 (photon+index)->plane 123.195.25.91 04/13 22:35
4F:→ WPC001:然後先把compiler的最佳化关掉看看吧 123.195.25.91 04/13 22:36
5F:→ WPC001:再去检查index是否合法吧... 123.195.25.91 04/13 22:37
6F:推 avhacker:通常都是某个变数没初始化的关系 140.123.19.235 04/13 23:07
7F:→ tonit:谢谢各位回覆 有些问题我可能会寄信询问 :) 130.126.76.76 04/16 09:21