作者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
推 godfat:檢查看看 p->plane 有沒有正確初始化? 220.135.28.18 04/13 13:37
推 hungche:試試看使用volatile對這個變數不做最佳化 219.84.124.89 04/13 14:08
→ WPC001:先把p->plane改成 (photon+index)->plane 123.195.25.91 04/13 22:35
→ WPC001:然後先把compiler的最佳化關掉看看吧 123.195.25.91 04/13 22:36
→ WPC001:再去檢查index是否合法吧... 123.195.25.91 04/13 22:37
推 avhacker:通常都是某個變數沒初始化的關係 140.123.19.235 04/13 23:07
→ tonit:謝謝各位回覆 有些問題我可能會寄信詢問 :) 130.126.76.76 04/16 09:21