0
우선 영어가 기본이 아니므로이 글을 쓰는 것이 어렵고 여기서 새로운 단어입니다. 안녕하세요 :)열거 형으로 구성된 동적 2D 배열을 만들 때 malloc을 사용할 때
가상 머신과 gcc에서 Linux Mint를 사용하고 있습니다. 나는 저주를 사용하고있다.
// Codes on the board
enum BoardCodes {
BC_FREE_CELL = 1, // Cell is free
BC_USED_BY_WORM = 2, // Cell occupied by worm
BC_FOOD_1 = 3, // Food type 1; if hit by worm -> bonus of type 1
BC_FOOD_2 = 4, // Food type 2; if hit by worm -> bonus of type 2
BC_FOOD_3 = 5, // Food type 3; if hit by worm -> bonus of type 3
BC_BARRIER = 6, // A barrier; if hit by worm -> game over
};
2)이 내 구조체 내부에 "웜", 세포 변수 :
(1)이 내 열거이며, 나는 시간이 오류를 해결하기 위해 노력 해왔다
enum BoardCodes **cells;
3. )이 내가 배열 생성하는 방법입니다 : ShowDialog를 내부
aboard->cells = malloc((aboard->last_row +2)*sizeof(int*));
if(aboard->cells == NULL) {
showDialog("Abbruch: Zu wenig Speicher","Bitte eine Taste drücken");
exit(RES_FAILED); // No memory -> direct exit
}
int y;
for (y = 0; y < aboard->last_row; y++) {
// Allocate array of columns for each y
aboard -> cells[y] = malloc((aboard->last_col + 2)*sizeof(int));
if((aboard -> cells[y]) == NULL) {
showDialog("Abbruch: Zu wenig Speicher. Code2","Bitte eine Taste drücken");
}
}
그것이 말하는을 "메모리 부족, 홍보 모든 열쇠 "
4.) 나는 그것을 gdb를 사용하여 디버깅했다.
void fillwithfreebcs(struct board* aboard)
{
int y=0;
int x=0;
//fill board and screen buffer with empty cels
for (y = 0; y < aboard->last_row; y ++)
{
for(x = 0; x < aboard->last_col ; x++) {
aboard->cells[y][x] = BC_FREE_CELL;
//placeItem(aboard,y,x,BC_FREE_CELL,SYMBOL_FREE_CELL,COLP_FREE_CELL);
}
}
}
너무 감사합니다 :
aboard->cells[y][x]=board_code;
(gdb) print x
$3 = 40
(gdb) print y
$4 = 10
(gdb) print aboard->last_col
$5 = 165
(gdb) print aboard->last_row
$6 = 28
(gdb) print board_code
$7 = BC_BARRIER
5.) 내가 배열의 값을 인쇄하려고했다 : 분할 오류가 여기에 발생
(gdb) print aboard->cells[1][1]
$9 = 3087007176
(gdb) print aboard->cells[1][2]
$10 = 3251580
을하지만 그들은 BC_FREE_CELL해야 많이 :)
(내가 enum 보드 코드 * 대신 int *를 사용하면 같은 오류 메시지가 나타납니다.)
rgds, Tobi.