XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Problem obtaining lock on back buffer

Last post 6/9/2007 1:16 PM by David Hunt. 1 replies.
  • 6/7/2007 5:46 PM

    Problem obtaining lock on back buffer

    Hi all,

    I've been working on some directdraw code from Andre Lamothe's book Tricks of the windows games programming gurus. I'm having a bit of trouble locking the back buffer. When I call lock() on the surface, it throws an error DDERR_SURFACEBUSY, apparently another thread has already locked the surface. However, I tried unlocking the surface first and I get an error saying that the surface is not locked. This confuses me.

    I've checked my code a few times and the main and init methods look the same as Andre's, except I did not define a custom palette. I have no idea why the back surface would be locked - can anyone help please?

    My initiailisation method (I'm pretty sure this is not where the problem is):
    int Game_Init()
    {
      if( FAILED( DirectDrawCreateEx( NULL, (void **)&lpDD,
    IID_IDirectDraw7, NULL ) ) )
        return(0);  //Error
     
      if( FAILED( lpDD->SetCooperativeLevel( hMainWnd, DDSCL_FULLSCREEN
    |
    DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE
    |
    DDSCL_ALLOWREBOOT ) ) )
    return(0);  //Error

      if( FAILED( lpDD->SetDisplayMode( SCREEN_WIDTH, SCREEN_HEIGHT,
    SCREEN_BPP, 0, 0 ) ) )
        return(0);  //Error

      //Setup direct draw surface description for primary surface
     
    memset( &ddsd, 0, sizeof(ddsd) );
      ddsd.dwSize = sizeof(ddsd);


      ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
      ddsd.dwBackBufferCount = 1;
      ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX
    | DDSCAPS_FLIP;

      if( FAILED( lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ) ) )
        return(0);  //Error

      ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

      if( FAILED( lpDDSPrimary->GetAttachedSurface( &ddsd.ddsCaps,
     &lpDDSBack ) ) )
        return(0);

      return(1);
    }



    And my main method looks like (the error is thrown calling lock()):
    int Game_Main()
    {
      if( window_closed )
        return(0);

      if( KEYDOWN( VK_ESCAPE ) )
      {
        SendMessage( hMainWnd, WM_CLOSE, 1, 0 );
        window_closed = 1;
      }

      memset( &ddsd, 0, sizeof(ddsd) );
      ddsd.dwSize = sizeof(ddsd);

      int dderrcode;
      if( FAILED( dderrcode = lpDDSBack->Lock( NULL, &ddsd,
    DLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, 0 ) ) )
      {
        return(dderrcode);
      }
    ...
    }

  • 6/9/2007 1:16 PM In reply to

    Re: Problem obtaining lock on back buffer

    Is the exception being thrown on the very first call to Game_Main or on the second call? If it's not on the first call, then check the rest of your Game_Main (and any functions it calls) to make sure that you are always unlocking the surface before exiting Game_Main.

    If it's on the first call, then I'm not sure what might be causing the exception.

    You could try reducing your Game_Main down to just lock/unlock/flip and see if the problem goes away. If it does, start adding in your code until the problem returns. Then you will know exactly what is causing it.

     

Page 1 of 1 (2 items) Previous Next