Jump to content
  • Advertisement
Sign in to follow this  
akira32

When does the surface UnlockRect

This topic is 3715 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!