[問題] Release Mode and Debug Mode
各位板友好
我遇到一個問題如下:
我正在做圖學作業 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
推
04/13 13:37, , 1F
04/13 13:37, 1F
推
04/13 14:08, , 2F
04/13 14:08, 2F
→
04/13 22:35, , 3F
04/13 22:35, 3F
→
04/13 22:36, , 4F
04/13 22:36, 4F
→
04/13 22:37, , 5F
04/13 22:37, 5F
推
04/13 23:07, , 6F
04/13 23:07, 6F
→
04/16 09:21, , 7F
04/16 09:21, 7F