Jump to content
  • Advertisement
Sign in to follow this  
CodyShort

SDL segfaults on exit

This topic is 2693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);
}

Share this post


Link to post
Share on other sites
Advertisement
You are not supposed to call SDL_FreeSurface() on the surface returned from SDL_SetVideoMode().

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!