views:

61

answers:

2

It gives me an access violation on the getmaxyx line (second line in the main function) and also gives me these two warnings:

LINK : warning LNK4049: locally defined symbol "_stdscr" imported
LINK : warning LNK4049: locally defined symbol "_SP" imported

Yes, it's the same code as in another question I asked, it's just that I'm making it more clear. And yes, I have written programs with pdcurses before with no problems.

#include <time.h>
#include <curses.h>
#include "Ball.h"
#include "Paddle.h"
#include "config.h"

int main(int argc, char *argv[])
{
    int maxY, maxX;
    getmaxyx(stdscr, maxY, maxX);

    Paddle *paddleLeft = new Paddle(0, KEY_L_UP, KEY_L_DOWN);
    Paddle *paddleRight = new Paddle(maxX, KEY_R_UP, KEY_R_DOWN);
    Ball *ball = new Ball(paddleLeft, paddleRight);

    int key = 0;

    initscr();
    cbreak();
    noecho();
    curs_set(0);

    while (key != KEY_QUIT)
    {
        key = getch();
        paddleLeft->OnKeyPress(key);
        paddleRight->OnKeyPress(key);
    }

    endwin();
    return 0;
}
+1  A: 

You need to call initscr before getmaxyx

R Samuel Klatchko
+1: Beat me by 7 seconds!
Moron
A: 

It has been a long time since I have used curses, but I would guess you need to call initscr() before any other curses call like getmaxyx.

Also, you probably are also missing some error checking on the return of initscr and need to use the return values properly (perhaps you have to pass it on to other curses method?).

Moron
Wish I could accept both, seeing as they were so close, but I'm going to accept Moron's for two reasons: 1. I know how it feels to miss something by just a little bit, and 2. because I imagine the only reason you missed it is because you were adding more to your answer, which is good. Sorry, R Samuel Klatchko, you did a good job too.
flarn2006