Sign in to follow this  

DirectDrawsurface gets lost????

This topic is 4814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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