Sign in to follow this  
akira32

When does the surface UnlockRect

Recommended Posts

akira32    112
Can I timely let surface UnlockRect after LockRect. Is the "<==position1" surface UnlockRect postion correct? Does it have any probelm about the pointer of "lrect_New.pBits"?
	HRESULT hr;

	LPDIRECT3DSURFACE9 pDestSurface_New;
	D3DLOCKED_RECT lrect_New;
	D3DSURFACE_DESC Desc;

	m_QVSM_pShadowMapSurf_Common->GetDesc(&Desc);
	V(m_pd3dDevice->CreateOffscreenPlainSurface(Desc.Width,Desc.Height,Desc.Format,D3DPOOL_SYSTEMMEM,&pDestSurface_New,NULL));//Must be D3DPOOL_SYSTEMMEM for MSDN
	V(m_pd3dDevice->GetRenderTargetData(m_QVSM_pShadowMapSurf_Common,pDestSurface_New));

	hr=pDestSurface_New->LockRect(&lrect_New,NULL,D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_READONLY);
	//hr=pDestSurface_New->UnlockRect();//<==position1

	for (LONG y=0;y<(LONG)Desc.Height;y++)
	{
		DWORD dwOffset = y*Desc.Width;

		for (LONG x=0;x<(LONG)Desc.Width;x++)
		{
			//float dwColor_New = ((float*)lrect_New.pBits)[y*(lrect_New.Pitch/sizeof(float))+x];//Y*Width+X
			float dwColor_New = ((float*)lrect_New.pBits)[y*Desc.Width+x];//Y*Width+X
			int c=12;
		}
	}

	hr=pDestSurface_New->UnlockRect();//<==position2

	SAFE_RELEASE(pDestSurface_New);

Share this post


Link to post
Share on other sites
jollyjeffers    1570
As far as I'm aware you cannot access the locked pointer outside of the lock itself - if it works then I'd be inclined to call "undefined behaviour". Test it with the RefRast and debug runtimes to be sure.

For this sort of design, especially if you're throwing the data off to a worker thread, it would be common to have a LockRect(), memcpy_s() then UnlockRect() pattern. Once you've grabbed yourself a copy of the locked data you can release the pointer, the lock and do whatever the hell you want with it [smile]

hth
Jack

Share this post


Link to post
Share on other sites

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