DirectDrawsurface gets lost????

Started by
0 comments, last by TheMillenium 19 years, 6 months ago
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 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
Advertisement
I think it is the CreateOffScreenSurface() function that throws the error. You return a pointer but as soon the function leaves the stuck all the variables that were created during the function call are also destroyed, you have to return the real surface not just a pointer to it.
_______________________________Manowar rulez the World!!

This topic is closed to new replies.

Advertisement