Original Post
I''m working on a DirectX Tetris clone, and the program is crashing each time it reaches the following code:
-------------------------------
-------------------------------
if(game_state == GAME_STATE_RUN)
{
DDSURFACEDESC2 ddsd; // directdraw surface description
// initialize... waaaait... we did this already
DDRAW_INIT_STRUCT(ddsd);
(!(lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL))) {
// error
return(0);
} // end if
// now ddsd.lPitch is valid and so is ddsd.lpSurface
// make a couple aliases to make code cleaner, so we don''t
// have to cast
int mempitch = (int)ddsd.lPitch;
UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface;
// Clear the surface
HDC xdc = GetDC(hwnd);
HBRUSH brush = (HBRUSH)CreateSolidBrush(RGB(0,0,0));
SelectObject(xdc, brush);
Rectangle(xdc,0,0,640,480);
ReleaseDC(hwnd, xdc);
// now unlock the primary surface
if (FAILED(lpddsprimary->Unlock(NULL)))
return(0);
// Create a bitmap surface
LPDIRECTDRAWSURFACE4 lpddsBitmap = NULL;
if(FAILED(lpddsBitmap->Lock(NULL, &ddsd,
DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL))) {
MessageBox(hwnd, "ERROR!", "ERROR!", MB_OK);
}
if ( ( lpddsBitmap = DDLoadBitmap( lpdd4, "Block1.bmp", 0, 0) ) == NULL )
return FALSE;
int BITMAP_WIDTH = 32;
int BITMAP_HEIGHT = 32;
RECT rcFrom;
rcFrom.left = 0;
rcFrom.top = 0;
rcFrom.right = BITMAP_WIDTH;
rcFrom.bottom = BITMAP_HEIGHT;
if ( FAILED( lpddsprimary->BltFast( 0, 0, lpddsBitmap, &rcFrom, DDBLTFAST_WAIT ) ) )
return FALSE;
lpDDSBitmap->Unlock(NULL);
// sleep a bit
Sleep(30);
// return success or failure or your own return code here
return(1);
} // End GAME_STATE_MAIN
-------------------------------
-------------------------------
I have ddutil.cpp/.h included, and there are no problems with any other areas of the code. I believe the problem occurs when locking the primary and bitmap surfaces. Any help would be appreciated.
- Steven Richards
- AKA HTML_Dude