Sign in to follow this  
vinb

Trying to get a back buffer working

Recommended Posts

I am making a blackjack game, but in the process of experimenting, I fear I have royally messed things up. I get a nasty error (Unhandled exception at 0x0041dabf in BlackJack.exe: 0xC0000005: Access violation reading location 0x00000000.) when the program gets to this line:
ddrval = lpsCards->GetAttachedSurface(&ddscaps, &lpBackBuffer);
    // create the main DirectDraw object
    DirectDrawCreateEx( NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL );

    ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL );
    if( ddrval != DD_OK )
    {
        lpDD->Release();
        return(false);
    }

    // Create the primary surface with 1 back buffer
    memset( &ddsd, 0, sizeof(ddsd) );
    ddsd.dwSize = sizeof( ddsd );

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

    ddrval = lpDD->CreateSurface( &ddsd, &lpsCards, NULL);
    
    ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
    ddrval = lpsCards->GetAttachedSurface(&ddscaps, &lpBackBuffer);

I have been trying to follow multiple tutorials and I'm at the point where I think I'm just confusing myself (not hard to do). Is this the proper way to set up a primary surface with a back buffer?

Share this post


Link to post
Share on other sites
I've taken a couple of more whacks at it and I'm finding that I can't even create the primary surface...

if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpDD, IID_IDirectDraw7, NULL)))
return(0);

ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL );

DDRAW_INIT_STRUCT(ddsd);

ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.dwBackBufferCount = 1;

ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;

// this fails for some reason
if (FAILED(lpDD->CreateSurface(&ddsd, &lpsCards, NULL)))
return(0);


Any idea why CreateSurface would fail?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this