Advertisement

SDL segfaults on exit

Started by May 08, 2011 01:56 AM
0 comments, last by Wooh 13 years, 6 months ago
Okay so im not quite sure why it is doing this. The following code compiles just fine, but when I try to add a new int into the Edu class it segfaults on exit. I've been trying to avoid posting but i honestly cannot figure this out.

/************
**************


main.cpp starts edu

*************
************/
#include "Edu.h"

int main()
{
Edu edu;
edu.Init(640, 480, 32, "Edu");
return 0;
}




/*******

Edu.h Class edu(main part of engine)

*******/


#ifndef EDU_H
#define EDU_H
#include "SDL/SDL.h"
#include <string>

class Edu
{
public:
Edu();
virtual ~Edu();

void Init(); // initializes sdl with default settings
void Init(int, int, int, std::string); //initializes sdl with custom settings
SDL_Event MainEvent;
protected:
private:
SDL_Surface * MainScreen; //screem surface

void Run();
void CleanUp();
bool Quit;
};

#endif // EDU_H





/******

Edu.cpp
Edu class definitions

*******/


#include "Edu.h"

Edu::Edu()
{

}

Edu::~Edu()
{

}

void Edu::Init()
{
SDL_Init(SDL_INIT_EVERYTHING);
MainScreen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
SDL_WM_SetCaption("Window", NULL);
Quit = false;
Run();
}

void Edu::Init(int WindowWidth, int WindowHeight, int WindowMode, std::string WindowName)
{
SDL_Init(SDL_INIT_EVERYTHING);
MainScreen = SDL_SetVideoMode(WindowWidth, WindowHeight, WindowMode, SDL_SWSURFACE);
SDL_WM_SetCaption(WindowName.c_str(), NULL);
Quit = false;
Run();
}

void Edu::Run()
{
while(!Quit)
{
while(SDL_PollEvent(&MainEvent))
{
if(MainEvent.type == SDL_QUIT)
{
Quit = true;
SDL_Quit();
}
}
}
CleanUp();
}

void Edu::CleanUp()
{
SDL_FreeSurface(MainScreen);
}
You are not supposed to call SDL_FreeSurface() on the surface returned from SDL_SetVideoMode().

This topic is closed to new replies.

Advertisement