Nov 3, 2010 at 1:40pm UTC
Hi!
Here's my code:
class Game {
public:
Game(SDL_Surface* scr=NULL,int x=800,int y=600,Uint32 flags=SDL_HWSURFACE|SDL_DOUBLEBUF,bool isSave=false);
virtual ~Game();
virtual void restart();
virtual void run();
virtual bool tick(int ms=33);
virtual void help();
virtual SDL_Surface* getSurface();
protected:
Uint32 rgb(Uint8 r,Uint8 g,Uint8 b);
void put(int x,int y,Uint32 color);
Uint32 get(int x,int y);
SDL_Surface *screen;
SDL_Event e;
Argos args;
int w, h, ms;
string name;
vector<string> scores;
int do_paint; //0 paint every frame, 1 paint at input, 2 paint manually
//type_info tie;
//void *data;
//void *return_value;
bool exit_program;
virtual void getScores();
virtual void keyDown(SDLKey key);
virtual void keyUp(SDLKey key);
virtual void mouseUp(SDL_MouseButtonEvent mbe);
virtual void mouseDown(SDL_MouseButtonEvent mbe);
virtual void mouseMove(SDL_MouseMotionEvent mme);
virtual void handleInput();
//virtual void setTie();
//virtual void* formatRValue();
virtual void update();
virtual void check();
virtual void updateGame();
virtual void drawScores(int x,int y);
virtual void paint();
};
nothing wrong with that. However, if I add a new variable I get a segmentation fault. It doesn't matter if it's an int or a pointer or something. I've had this problem before, and I usually solve it by moving some of the variables.
Game_Vars {
void * data;
...
};
Game {
Game_Vars * gv;
};
There seems to be a limit on the number and size of variables in a class. I'm using g++ on Linux.
Nov 3, 2010 at 1:41pm UTC
You have a memory bounds overwrite problem in your app.
Nov 3, 2010 at 6:50pm UTC
Thanks. What can I do to solve it?
Nov 3, 2010 at 7:20pm UTC
Since we don't have the code...break when you segfault and see about where it happens. Then fix the problem with whatever variable you are messing with at the time.
Nov 7, 2010 at 10:06am UTC
I've tried something else. I derived a class called Boardgame from Game. A segmentation fault occurs when I try to draw something.
void Game::paint(){
/*glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
glVertex2f(200,200);
glVertex2f(300,300);
glVertex2f(200,400);
glEnd();*/
}
I have to cancel out this entire function. if I call Game directly, it works fine.