XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

When does the surface UnlockRect

Last post 5/14/2008 3:49 PM by David Hunt. 1 replies.
  • 5/14/2008 11:13 AM

    When does the surface UnlockRect

    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"?

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
      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);
  • 5/14/2008 3:49 PM In reply to

    Re: When does the surface UnlockRect

    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.

     

Page 1 of 1 (2 items) Previous Next