Can I timely let surface UnlockRect after LockRect.Is the "<==position1"(line9) surface UnlockRect postion correct? Does it have any probelm about the pointer of "lrect_New.pBits"?
12345678910111213141516171819202122232425262728
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);
You cannot unlock the surface until you are done accessing the pixel data. Once unlocked, the memory pointed to can (and likely will) be invalid.