看板 C_and_CPP 關於我們 聯絡資訊
----------------抱怨------------------ 該死的BCB 常常出現一對不明BUG害我永遠在DEBUG -------------------------------------- ----------------描述------------------ 這個問題是 我程式一開始有 定義 #define H 150 #define W 200 這樣子方便修改 靜態矩陣又容易DEBUG 驚人的問題出現了 當我把 #define H 150 #define W 200 改成 #define H 512 #define W 512 跑出 Stack Overflow..... -------------------------程式描述--------------------------- 程式是跑到 void __fastcall TForm1::Button3Click(TObject *Sender) { A(); //產生隨機高斯分布 B(); //SVD } error %$@# Stack Overflow 然後箭頭指到 --> void B() 一開頭 { ... } 所以我懷疑錯誤是在 附程式 A(); 產生 在這裡秀給大家看小弟寫的超弱程式 不好意思 到底那裡出問題 以下是 一個高斯分布 打散隨機排列組合 32767是rand()的極限 我不知道 為什麼 150*200 可以過 512*512 出錯 是哪裡爆掉了 有請高手幫忙 使用CODE GUARD 他有產生一個OVERRUN在最後一段 for(int y=0;y<H;y++) { for(int x=0;x<W;x++) { if(x==0 && y!=0) { data[y][x]=data1[RandomIndex[y]/W][Rand } else if(y==0 && x!=0) { data[y][x]=data1[RandomIndex[x]/W][Rand } else { --------------> data[y][x]=data1[RandomIndex[x*y]/W][Ra } } } -----------------------------程式原始碼------------------------ float z,sum; z++; sigma=1; mean=127; for(int x=0;x<256;x++) { z=-(x-mean)/sigma; gaussian[x]=(1/pow(pi,0.5))*exp(-pow(z,2)/2) ; sum+=gaussian[x]; } for(int x=0;x<256;x++) { gaussian[x]=gaussian[x]/(sum+1); //normalize gaussian[x]=gaussian[x]*(W*H); //distribution point } sum=0; for(int x=0;x<256;x++) { sum+=gaussian[x]; } //random index randomize(); int n=1+(H*W)/32767; //If Image > 32767 for(int x=0;x<H*W;x++) { RandomIndex[x]=x+1; } for(int x=0;x<H*W;x++) { if(H*W > 32767) { int k,t; k=(rand()*n) % (H*W); if(k < H*W) { t=RandomIndex[k]; RandomIndex[k]=RandomIndex[x]; RandomIndex[x]=t; } } else { int k,t; k=rand() % (H*W); t=RandomIndex[k]; RandomIndex[k]=RandomIndex[x]; RandomIndex[x]=t; } } //Sort && Put Index int count=0; n=0; for(int x=0;x<W;x++) { for(int y=0;y<H;y++) { data[y][x]=n; data1[y][x]=n; count++; if(count >= gaussian[n]) { if(n<255) { count=0; n++; } else { n=n; } } } } for(int y=0;y<H;y++) { for(int x=0;x<W;x++) { if(x==0 && y!=0) { data[y][x]=data1[RandomIndex[y]/W][RandomIndex[y]%W]; } else if(y==0 && x!=0) { data[y][x]=data1[RandomIndex[x]/W][RandomIndex[x]%W]; } else { data[y][x]=data1[RandomIndex[x*y]/W][RandomIndex[x*y]%W]; } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.64.88.58
wa120:我怎麼好像記得pow()也會overflow 但是不確定是不是這個問題 02/17 17:17
visor:你一堆陣列宣告的大小都不知 02/17 17:24
NoobImage:全部都是[H][W]或一維[H*W]啊 02/17 17:40
NoobImage:只有這個 是gaussian[256] 02/17 17:41
NoobImage:pow()不可能 那串數值是定值 02/17 17:43
ledia:stack 預設只有 1M, 512x512 如果 type 是 int 一個就超過了 02/17 17:49
TroyLee:該死的BCB? 02/17 18:46
ledia:嗯 我想應該是原 po 的誤會, 錯怪 BCB 了 02/17 18:54
rockmanray:BCB很nice的,這其中一定有什麼誤會 02/17 19:48
NoobImage:...我剛把stack加倍 過了 不過程式關閉會出現錯誤 02/17 20:06
ledia:我建議你用動態配置, 程式關閉會有錯這大概也是 stack 問題 02/18 00:06