SDL_SetVideoMode挂起进程

时间:2010-10-25 09:41:02

标签: c++ graphics sdl

在我的程序初始化期间,我在SDL_Init()之后调用SDL_SetVideoMode()并且它正在挂起我的程序。 执行程序时,如果我在挂起期间按下Ctrl-C,它将继续正常运行,一切正常。

显然,每次都必须中断SDL_SetVideoMode()并不理想!任何人对这可能有什么想法?

这是我正在使用的简单测试代码:

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

1 个答案:

答案 0 :(得分:1)

我发现了问题。显示后我根本没有释放图像表面,这意味着没有正确调用SDL_Quit! 修复了以下示例中的代码:

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;
}
相关问题