Click to See Complete Forum and Search --> : Why does the surface gets lost?


Daniel M
October 7th, 2004, 11:11 PM
I am trying to gradually blend a bitmap onto the primary surface, it works one time but when I try to do it again, the lpDDSBack.lpSurface is set to 0x000000,which it was not in the first execution!, and I am getting an exception error,

how could this be?

First I load the bitmap into the directdrawsurface lpDDSBitmap using the DDLoadBitmap function!

win* p;


typedef struct win
{
LPDIRECTDRAW lpDD;
LPDIRECTDRAWSURFACE lpDDSPrimary;
LPDIRECTDRAWSURFACE lpDDSBack;
LPDIRECTDRAWSURFACE lpDDSBitmap;
LPDIRECTDRAWCLIPPER lpClipper;
}


p->lpDDSBitmap=DDLoadBitmap(p,p->lpDD,L"crystalcocktail.bmp");

IDirectDrawSurface * DDLoadBitmap(win* p,IDirectDraw *pdd, LPCTSTR szBitmap)
{
HBITMAP hbm;
BITMAP bm;
IDirectDrawSurface *pdds;

hbm=SHLoadDIBitmap(szBitmap);
if (hbm == NULL){
return NULL;
}

GetObject(hbm, sizeof(bm), &bm); // get size of bitmap

/*
* create a DirectDrawSurface for this bitmap
* source to function CreateOffScreenSurface() follows immediately
*/

pdds = CreateOffScreenSurface(pdd, bm.bmWidth, bm.bmHeight);
if (pdds) {
DDCopyBitmap(pdds, hbm, bm.bmWidth, bm.bmHeight);
}

DeleteObject(hbm);

return pdds;
}

And then I Blit the bitmap surface to the Backbuffer using the Flip_Bitmap_To_Back(p):

bool_t Flip_Bitmap_To_Back(win* p)
{
HRESULT ddrval;
RECT rcRectSrc;
RECT rcRectDest;
POINT pt;

// first we need to figure out where on the primary surface our window lives
pt.x = 0; pt.y = 0;
ClientToScreen(p->Wnd, &pt);
GetClientRect(p->Wnd, &rcRectDest);
OffsetRect(&rcRectDest, pt.x, pt.y);
SetRect(&rcRectSrc, 0, 0, 472, 286); //var 472 286
ddrval =IDirectDrawSurface_Blt(p->lpDDSBack, &rcRectDest, p->lpDDSBitmap, &rcRectSrc, DDBLT_WAIT, NULL);
if(ddrval==DDERR_SURFACELOST){
restoreAll(p);
}

And then finally I uses the blendfunction

BltAlpha(p->lpDDSPrimary,p->lpDDSBack,0,0,&r,128,RGBMODE_565); //var RGBMODE_565
}


If I do this one more time the exception error occurs, and I donīt know why, could it be that the surface gets lost in some of the actions or?????

Please help me someone, thanks Dani