title: SDL Surfaces Randomly Lock
body: <p>I am a newbie to SDL, and starting to learn some of it, and encountered an interesting problem. The window for the program would flash, then disappear forever. Also, there would occasionally be an exec error with <code>SDL_BlitSurface</code>. <code>SDL_GetError()</code> shows it to be a surface locking. However, when checking the screen surface's locks, by using <code>-&gt;locked</code>, the screen surface would always have a random number amount of locks, ranging from positive to negative numbers.</p>
  
  <p>Manager class:</p>
  
  <pre><code>//apply image
  if(SDL_BlitSurface(SDLProcess::getInstance().getImage(0), NULL, SDLProcess::getInstance().getScreenSurface(), NULL) &lt; 0)
  {
  
      ErrorManagement::callSDLError();
  }
  </code></pre>
  
  <p>Screen Surface class:</p>
  
  <pre><code>ScreenSurface::ScreenSurface(SDL_Window* window)
  {
  //std::cout &lt;&lt; window &lt;&lt; std::endl;
  p_screensurface = SDL_GetWindowSurface(window);
  
  assert(p_screensurface != NULL);
  
  //std::cout &lt;&lt; p_screensurface &lt;&lt; std::endl;
  }
  
  ScreenSurface::~ScreenSurface()
  {
      printf("screen surface destroyed");
  }
  
  SDL_Surface* ScreenSurface::getScreenSurface()
  {
  //std::cout &lt;&lt; p_screensurface &lt;&lt; std::endl;
  return p_screensurface;
  }
  </code></pre>
  
  <p>Error message in console (the top number is the number of locks and the lower is the error message):</p>
  
  <pre><code>37792424
  SDL Error: Surfaces must not be locked during blit
  </code></pre>
  
  <p>and another example:</p>
  
  <pre><code>42068296
  SDL Error: Surfaces must not be locked during blit
  </code></pre>