tags:

views:

22

answers:

1

During initialisation of my program I call SDL_SetVideoMode() just after SDL_Init() and it is hanging my program. When executing the program, if I press Ctrl-C during the hang it will continue as normal and all works fine.

Obviously having to interupt SDL_SetVideoMode() every time isn't ideal! Anyone have any ideas on what this could be?

Here's the simple test code I'm using:

main.cpp

int main(int argc, char* argv[])
{
  Presentation* p = new Presentation();  //Presentation is used to display JPEGs
  p->Initialise();

  while (p->hasSlides())
  {
    p->DisplayNextSlide();
    sleep(5);
  }
  return 0;
}


Presentation.cpp

Presentation::Initialise()
{
  SDL_Init(SDL_INIT_VIDEO);
  m_pScreen = SDL_SetVideoMode(1280,720,16, SDL_DOUBLEBUF | SDL_FULLSCREEN);
  if (!m_pScreen)
  {
    //error handling...
  }

  SDL_ShowCursor(SDL_DISABLE);
  initialised = true;
}


SDL_Surface* m_pImage;

Presentation::DisplayNextSlide()
{
  m_pImage = IMG_Load(filename);
  if(!m_pImage)
  {
    //error handling...
  }

  SDL_BlitSurface(m_pImage,0,m_pScreen,0);
  SDL_Flip(m_pScreen);
}
A: 

I've since found the problem. I was simply not freeing the image surface after displaying which meant SDL_Quit wasn’t being called correctly! Fixed code from example below:

SDL_Surface* m_pImage;

 Presentation::DisplayNextSlide()
 {
   m_pImage = IMG_Load(filename);
   if(!m_pImage)
   {
    //error handling...
   }

   SDL_BlitSurface(m_pImage,0,m_pScreen,0);
   SDL_Flip(m_pScreen);
   SDL_FreeSurface(m_pImage);
   m_pImage = NULL;
}
peacemaker