Original Post
Hey, I've been learning SDL with Lazy Foo's tutorials (thanks btw, they're awesome), and I'm having a few problems with my code. Basically, when I run the program, the screen flashes black for a second (I'm running this in full screen) and then closes without any message. When I comment out the line Map* tempLevel = new Map("test.map", NULL); the program runs fine (just displays a black screen until user quits). I started playing with my constructor to see what the problem is, but it still quits even if I comment out everything in the constructor. I realize this isn't very descriptive, but I'm not sure how to get debug information out of SDL .. if someone could explain even that, it would be very helpful. The relevant (I think) portions are below (I commented out a lot of the methods to make sure they're not the ones causing the problem): Also, would it just be easier to upload the complete source somewhere? (It's not that big)
int main( int argc, char* args[] ) {
bool quit = false;
Timer fps;
if ( initAll() == false )
{
return 1;
}
//temp code
//Player* player;
//player->setVar(100, 50);
Map* tempLevel = new Map("test.map", NULL);
while ( quit == false )
{
fps.start();
while ( SDL_PollEvent( &event ) )
{
if ( event.type == SDL_QUIT )
{
quit = true;
break;
}
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
{
quit = true;
break;
}
//tempLevel->eventHandler(event);
}
//player->movePlayer();
//tempLevel->drawMap(screen);
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
//Cap the frame rate
if ( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
fps.start();
}
}
delete tempLevel;
return 0;
}
class Map{
private:
int height;
int width;
//camera offsets
long xCoordOffset;
long yCoordOffset;
Tile* map;
Player* player;
//Enemy* enemies;
public:
Map(std::string, Player*);
~Map();
//map camera functions
void centerCamera();
void scrollCamera();
void checkCameraOOB();
//drawing map
void drawMap(SDL_Surface*);
//event handler
void eventHandler(SDL_Event);
Tile* getTile(long, long);
};
//Constructor
Map::Map(std::string filename, Player* player){
/*std::fstream file(filename.c_str());
file >> width >> height;
map = new Tile[width * height];
this->player = player;
this->player->setMap(this);
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
file >> map[i*width+j].tileType;
map[i*width+j].passable = PASSABLE[map[i*width+j].tileType];
if(map[i*width+j].tileType == 99){
this->player->placePlayer(j * TILE_HEIGHT + (TILE_HEIGHT - PLAYER_SPRITE_HEIGHT) / 2, i * TILE_HEIGHT + (TILE_HEIGHT - PLAYER_SPRITE_HEIGHT) / 2);
map[i*width+j].tileType = 0;
}
}
}
centerCamera();*/
}