Advertisement

Can't lock offscreen surface...

Started by August 13, 2000 11:10 PM
0 comments, last by Pyro_256 24 years, 4 months ago
I''m using this function to initialize offscreen surfaces: DDWrap::InitOffScreen(LPDIRECTDRAWSURFACE offscreen, int width, int height){ memset(&ddsd,0,sizeof(ddsd)); //clear out ddsd ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS |DDSD_WIDTH| DDSD_HEIGHT; ddsd.dwWidth = width; //set width ddsd.dwHeight = height; //set height ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; if(lpdd->CreateSurface(&ddsd, &offscreen, NULL)!=DD_OK){ EndProg(3); //end the program if an error occurs return(0); } return(1); } This function works fine and doesn''t crash the program, but as soon as I try to lock the offscreen surface, it crashes: memset(&ddsd,0,sizeof(ddsd)); // clear out ddsd ddsd.dwSize = sizeof(ddsd); //set the size feild destination->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); // this line crashes Note: this is in another function that takes destination as a surface onto which to load a bitmap. When I give a primary or secondary surface as destination, it works fine, but if I use an offscreen surface, it crashes on the line where it trys to lock the surface.
I found the problem, but why it''s a problem I have no idea:

when I changed to function to take a pointer to a pointer (**), it no longer causes it to crash. Previously, for some reason, the changes made to the pointer didn''t stay after the function is complete.

DDWrap::InitOffScreen(LPDIRECTDRAWSURFACE *offscreen, int width, int height){

... the rest of the code

if(lpdd->CreateSurface(&ddsd, offscreen, NULL)!=DD_OK){
EndProg(3); //end the program if an error occurs
return(0);
}


This now works for some reason.

This topic is closed to new replies.

Advertisement