# Problems with Set / GetRenderTarget() and Present afterwards

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

## Recommended Posts

Hi there! I have a strange problem: I wanted to experiment with multiple render targets, so I did the following: 1. Created a set of textures with usage set to D3DUSAGE_RENDERTARGET and got their surfaces at level 0. Works fine 2. Called GetRenderTarget() to store the back buffer surface in order to be able to restore it. This call succeeds. 3. Called SetRenderTarget() for my 4 render targets. Succeed. 4. Render some stuff with a simple pixel shader that puts something on all 4 render targets. works. 5. Called SetRenderTarget() with the back buffer surface as a parameter. Succeeds, too. 6. Called Present(0,0,0,0). Application stops here with a breakpoint somewhere in "ntdll.dll". So after that I tried looking at what the backbuffer surface contains with the debugger and it seems it is totally screwed up. For example the width and height are both 1 while MultiSampleType and MultiSampleQuality contain the width and height of the surface. Weird.... I´ll post some code:
this->m_pRTBackBuffer = NULL;
HRESULT hr = this->m_pDirect3DDevice->GetRenderTarget(0, &this->m_pRTBackBuffer);
if(FAILED(hr))
{
MessageBox(NULL, "GetRenderTarget failed!", "", MB_OK);
}

hr = this->m_pDirect3DDevice->SetRenderTarget(0, this->m_pRTColorSurface);
if(FAILED(hr))
{
MessageBox(NULL, "SetRenderTarget for ColorTexture failed!", "", MB_OK);
}
this->m_pDirect3DDevice->SetRenderTarget(1, this->m_pRTNormalsSurface);
if(FAILED(hr))
{
MessageBox(NULL, "SetRenderTarget for NormalTexture failed!", "", MB_OK);
}
this->m_pDirect3DDevice->SetRenderTarget(2, this->m_pRTDepthSurface);
if(FAILED(hr))
{
MessageBox(NULL, "SetRenderTarget for DepthTexture failed!", "", MB_OK);
}
this->m_pDirect3DDevice->SetRenderTarget(3, this->m_pRTSpecularSurface);
if(FAILED(hr))
{
MessageBox(NULL, "SetRenderTarget for SpecTexture failed!", "", MB_OK);
}

this->m_pDirect3DDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.f, 0);
this->m_pDirect3DDevice->BeginScene();

//Rendering

this->m_pDirect3DDevice->EndScene();
hr = this->m_pDirect3DDevice->SetRenderTarget(0, this->m_pRTBackBuffer);
if(FAILED(hr))
{
MessageBox(NULL, "Reverting to backbuffer failed!", "", MB_OK);
}
this->m_pRTBackBuffer->Release();
this->m_pRTBackBuffer = NULL;
this->m_pDirect3DDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0, 0), 1.f, 0);

this->m_pDirect3DDevice->Present(0,0,0,0);  // breaks here


m_pRT... are textures (LPDIRECT3DTEXTURE9) created with D3DUSAGE_RENDERTARGET. m_pRT...Surface are the surfaces (LPDIRECT3DSURFACE9) retrieved through GetSurfaceLevel(0,...). m_pRTBackBuffer is just a LPDIRECT3DSURFACE9. Since I get none of the message boxes I assume everything is fine. I know this is no good practice and I´ll do that error handling more smoothly as soon as I got this stuff working just once. But I´m totally clueless why a) the back buffer surface seems to be screwed up and b) the call to Present() doesn´t work. I´m using Visual Studio 2005 and DXSDK Februar 2006. Any tips and/or links to simple tutorials regarding the usage of render targets appreciated. Thx for your reading and any help!

##### Share on other sites
What does the debug runtime have to say? (Control Panel/DirectX, Direct3D, Select Debug Runtime, put debug level slider somewhere near the middle)

##### Share on other sites
At startup (when I initialise the renderer) I get a "BackBufferCount not specified, considered default 1" warning, after that some "Ignoring redundant SetSamplerState" warnings due to some code that loads meshes.
Other than that no output from debug runtimes, especially none regarding the call to Present().

fixed the BackBufferCount not specified thing by setting it to 1.
[/edit]

##### Share on other sites
When does the data for the backbuffer get messed up? Is it valid just after GetRenderTarget?

##### Share on other sites
Contains that stuff right after GetRenderTarget(). Do I have to set something up in VS2005 to get proper debugging info about D3D objects? I ask because for example if I check on the PresentationParams of the device object, they seem to be totally screwed, too, and many objects only contain an IUnkown object.

##### Share on other sites
You need to define D3D_DEBUG_INFO in your project (I set it in the project setting preprocessor defines).

##### Share on other sites
ah, thx. Did that and checked the surface again, now seems to be fine. Furthermore the call to present seems to work now. However I don´t understand how defining D3D_DEBUG_INFO would change that.

And I seem to be getting a different breakpoint now, again in "ntdll.dll", but when doing something with a vector::iterator.... completely unrelated to the render target stuff I tried out today. This starts to confuse me, I think I´ll take a break and look into it later.

the breakpoint getting called with the vector::iterator disappeared for no obvious reason. But now I get a breakpoint when calling CloneMesh(...) on a LPD3DXMESH...
I´m really confused about that, as it only appeared when I added the textures and surfaces for MRT to the renderer class.
[/edit]

##### Share on other sites
Ouch, that hurt....
the breakpoints appeared due to a Break on AllocID I setup to find a memory leak right before doing that MRT thing...
sry for bothering you, if I did.
Everything´s working now as supposed.

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628724
• Total Posts
2984404

• 25
• 11
• 10
• 16
• 14