# problem about write the back buffer

This topic is 3640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I meet a problem when I want to lock a back buffer under DXUT framework. I do change the present parameter flag to D3DPRESENTFLAG_LOCKABLE_BACKBUFFER, and in OnD3D9FrameRender I call :
[source lang = "c"]
// test to modify the backbuffer
IDirect3DSurface9* pSurface;
V(pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&pSurface));
D3DLOCKED_RECT lockedRect;

D3DSURFACE_DESC sd;
pSurface->GetDesc(&sd);

int pitch = lockedRect.Pitch;
DWORD* pBits = reinterpret_cast<DWORD*>(lockedRect.pBits);

for (int i = 0; i < 1; ++i)
{
int x = rand() % sd.Height;
int y = rand() % sd.Width;
*(pBits + y + x * pitch) = D3DCOLOR_XRGB(rand()%256,rand()%256,rand()%256);
}
pSurface->UnlockRect();
SAFE_RELEASE(pSurface);


when debuging, i check the sd(surface_desc),all data are all right. But the data pSurface pointing to are mistake:
-		pSurface	0x001ebee0 {Name=0x00000016 <Bad Ptr> Width=1 Height=67108865 ...}	IDirect3DSurface9 *
+		IDirect3DResource9	{...}	IDirect3DResource9
+		Name	0x00000016 <Bad Ptr>	const wchar_t *
Width	1	unsigned int
Height	67108865	unsigned int
Usage	4	unsigned long
Format	D3DFMT_UNKNOWN	_D3DFORMAT
Pool	D3DPOOL_DEFAULT	_D3DPOOL
MultiSampleType	640	_D3DMULTISAMPLE_TYPE
MultiSampleQuality	480	unsigned long
Priority	0	unsigned long
LockCount	22	unsigned int
DCCount	0	unsigned int
+		CreationCallStack	0x00000007 <Bad Ptr>	const wchar_t *


I think the value of width and height replace the value of MultiSampleType and MultiSampleQuality... Why there is an offset? and when i write the back buffer, it's overflow and the shutdown. Need help ,thx.

##### Share on other sites
Quote:
 Original post by smile55I meet a problem when I want to lock a back buffer under DXUT framework.I do change the present parameter flag to D3DPRESENTFLAG_LOCKABLE_BACKBUFFER,and in OnD3D9FrameRender I call :*** Source Snippet Removed ***when debuging, i check the sd(surface_desc),all data are all right. But the data pSurface pointing to are mistake:*** Source Snippet Removed ***I think the value of width and height replace the value of MultiSampleType and MultiSampleQuality... Why there is an offset?and when i write the back buffer, it's overflow and the shutdown.Need help ,thx.
I really wouldn't trust the watch windows for D3D objects like that. You need to make sure you're running the debug runtimes, and you have the D3D_DEBUG_INFO preprocessor definition defined. If you want to check data for the backbuffer, use IDirect3DSurface9::GetDesc().

Have you actually verified that there's a problem here, aside from what's seen in the watch window?

##### Share on other sites
thank you for reply.

i find the problem...I change the LockedRect.pBit to a DWORD* pointer, but forget to divide pitch by 4.

May be as you say, I can't believe the value in the watch window. The second time i trace pointer to the surface, the watch window didn't show so many fields as before...

Thank you.

##### Share on other sites
I'd recommend against using a lockable back buffer, for performance reasons. You can update the back buffer with rendering (or a copy), and use GetRenderTargetData to get it.

What kind of use did you have in mind?

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009840
• ### Who's Online (See full list)

There are no registered users currently online

×