我在開發C++應用程序。我已經分配了內存,但即時獲取superfile.cpp中的錯誤Thread 1: EXC_BAD_ACCESS (code=2,address=0x8)
。這裏是我的代碼:線程1:EXC_BAD_ACCESS(code = 2,address = 0x8)錯誤C++
superfile.h
struct Node{
Voxel *data;
Node *next;
};
superfile.cpp
int* cnt =(int*)calloc(_width*_height,sizeof(int));
Voxel *temp =(Voxel *)calloc(_width*_height,sizeof(Voxel));
Node *list=(Node *)calloc(_width*_height*2,sizeof(Node));
list[(_width*_height)+l].next = list[_width*yy + xx].next->next; // Thread 1: EXC_BAD_ACCESS (code=2,address=0x8) Error c++
調試變量的值之後爲:
_width=60
_height=45
l=3
yy=4096
xx=-3345
任何想法是什麼g在嗎?謝謝
什麼是'xx'和'yy'? – ForceBru 2015-03-03 13:13:22
@ForceBru xx = -3345和yy = 4096並聲明爲int xx =(int)floor(x + 0.5); int yy =(int)floor(y + 0.5); – 2015-03-03 13:16:44
我的意思是,他們從哪裏來?是你手動設置這些值還是以某種方式進行評估? – ForceBru 2015-03-03 13:18:23