Chenxi Yuan
Chenxi Yuan

Reputation: 164

error of initscr() function in ncurses.h library using xcode

We are trying to use ncurses library to build a terminal game. The initscr() function somehow returns an error message with no extra information. We are not sure why initscr() throws an error, and what we should do to debug it.

TerminalView::TerminalView(ViewModel* vm) {
this->vm = vm;
this->col_size = vm->get_col_size();
this->row_size = vm->get_row_size();
this->player_pos = vm->get_player_pos();
this-> enemy_pos = vm->get_enemy_pos();
this-> projectilePos = vm->getProjectilePos();

//initialize ncurses status
clear();
initscr();
noecho();
cbreak();
keypad(stdscr, TRUE);
curs_set(0);
}

Upvotes: 0

Views: 548

Answers (1)

2785528
2785528

Reputation: 5566

I suspect that clear() (which calls wclear(stdscr)) uses stdscr before it has been created. In my latest ncurses project, I captured the following comment (not sure from where):

   // To initialize the curses, the routine initscr() or
   // newterm() must be called before any of the other routines
   // that deal with windows and screens are used.  The routine
   // endwin() must be called before exiting. 

Try commenting out the "clear()", which I think you do not need anyway as it is one of the sometimes annoying things ncurses does too much of.

Upvotes: 1

Related Questions