Skip to main content
GameDev.net gamedev.net
🔒 Locked

Error Locking Surface... DDERR_SURFACELOST

Started by ACAC Jan 22, 2002 at 3:37 PM 2 replies 7.5k views
Original Post
ACAC
ACAC
Ive got an error when I lock my surface, I cant figure out why, the return code is DDERR_SURFACELOST, but where does it lose the surface!?? The pixels arent drawn eitha...
  
int GameMain()
{
	HRESULT hret;


	if(KEYDOWN(VK_ESCAPE)) { 
		UnInit();
		PostQuitMessage(0); }

	CLEARMEM(ddsd);

	hret = lpddsback->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); // this is possibly the offending line

	if(hret != DD_OK)
	{		
		ERR(hret);
		return 1;
	}

	UCHAR *videomem = (UCHAR*)ddsd.lpSurface;


	for(int x = 0; x < 500; x++)
	{
		for(int y = 0; y < 500; y++)
		{
	videomem[x + y * ddsd.lPitch] = _RGB(50,0,0);
		}
	}

	hret = lpddsback->Unlock(NULL);
	if(hret != DD_OK)
	{		
		ERR(hret);
		return 1;
	}

	hret = lpddsprimary->Flip(NULL,DDFLIP_WAIT);
	if(hret != DD_OK)
	{		
		ERR(hret);
		return 1;
	}

	return 0;
}
   
Edited by - ACAC on January 22, 2002 4:41:04 PM
gmcbay
gmcbay
A surface is ''lost'' when it is flushed out of video memory. This could happen for a number of reasons, one of the most common is the screen mode changes (fullscreen to windowed)..

If a DX call returns an error regarding the surface being lost, you must call the restore method (lpddsback->Restore(); should work in your case) before trying to access it again.
ACAC
ACAC
Hmmmm, ok I added that in, but now when I run it, it seems to put pixels on the screen, well garbled on the right of it, then when I exit the window goes smaller, like ( halfway through changing the screen size ) then it gives me an illegal operation error.

HM!!!
It has to be somthing to do with the back buffer, I dont know what though, well heres my init code.....

  
int Game_Init()
{
HRESULT hret;

hret = DirectDrawCreate(NULL, &lpdd, NULL);
if(hret != DD_OK)
{
ERR(hret);
return 1;
}

hret = lpdd->QueryInterface(IID_IDirectDraw4,(LPVOID*)&lpdd4);
if(hret != DD_OK)
{
ERR(hret);
return 1;
}

if(WINDOWED >= 1)
{
hret = lpdd4->SetCooperativeLevel(Ghwnd,DDSCL_NORMAL);
if(hret != DD_OK)
{
ERR(hret);
return 1;
}
hret = lpdd4->SetDisplayMode(400,400,8,NULL,NULL);
if(hret != DD_OK)
{
ERR(hret);
return 1;
}
}
else
{
hret = lpdd4->SetCooperativeLevel(Ghwnd,DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE);
if(hret != DD_OK)
{
ERR(hret);
return 1;
}

hret = lpdd4->SetDisplayMode(SW,SH,SBPP,NULL,NULL) ;
if(hret != DD_OK)
{
ERR(hret);
return 1;
}
}


// clear out DDSD

CLEARMEM(ddsd);
//Sort the flags

ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.dwBackBufferCount = 1;

// request a complex flippable surface

ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;

hret = lpdd4->CreateSurface(&ddsd, &lpddsprimary, NULL);
if(hret != DD_OK)
{
ERR(hret);
return 1;
}

ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

// get the backbuffer

hret = lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps,&lpddsback);
if(hret != DD_OK)
{
ERR(hret);
return 1;
}

return 0;
}



if thats any use, thanks........

OldGuy
OldGuy
I believe you have to restore all surfaces, including back buffer(s). Also, I believe you have to redraw the surface after the restore.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.