所以当我尝试使用ncurses绘制一个小房间时,我一直在运行这个段错误
GDB输出:
0x00007ffff76477c5 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff7649558 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff764b760 in malloc () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007ffff7bcb924 in _nc_printf_string ()
from /lib/x86_64-linux-gnu/libncurses.so.5
#4 0x00007ffff7bc70af in vwprintw ()
from /lib/x86_64-linux-gnu/libncurses.so.5
#5 0x00007ffff7bc7358 in mvwprintw ()
from /lib/x86_64-linux-gnu/libncurses.so.5
#6 0x0000000000401037 in drawRooms (rooms=0x6130b0) at src/draw.c:69
#7 0x0000000000400e88 in drawBoard (p=0x613040,
filepath=0x401bf4 "assets/input.txt") at src/draw.c:28
#8 0x0000000000400d7b in run (name=0x604010 "name",
path=0x401bf4 "assets/input.txt") at src/rogue.c:19
#9 0x0000000000400d3c in main (argc=1, argv=0x7fffffffe038) at src/main.c:24
drawRooms函数第69行的代码是:
mvwprintw (stdscr, pos.y, pos.x + x, "-");
使用gdb我检查了pos.y,pos.x和x的值并得到了它的值。因此我认为它是ncurses中的实际mvwprintw函数。我认为。这个错误发生在我正在绘制的另一个函数中,但我只是评论它,希望以后能够搞清楚。然而它开始发生在这里
我该怎么做才能解决这个问题?
编辑:
void drawRooms(Room * rooms)
{
int t = 0;
int x = 0, y = 0;
Position pos;
for(t=0;t<MAX_RM_AMNT;t++)
{
pos = rooms[t].pos;
for(x=0;x<rooms[t].width;x++) // the top/bottom
{
mvwprintw (stdscr, pos.y, pos.x + x, "-"); //segfaults here and any other mvwprintw
mvwprintw (stdscr, pos.y+rooms[t].height, pos.x + x, "-");
}
for(y=1;y<rooms[t].height;y++)
{
mvwprintw (stdscr, pos.y+y, pos.x, "|");
mvwprintw (stdscr, pos.y+y, pos.x+rooms[t].width, "|");
}
}
refresh();
return;
}
编辑2:
做一个简单的
mvwprintw(stdscr, 0,0,"X");
代替原始代码,仍会创建段错误