Sign in to follow this  

[DirectX] RenderTarget not resetable!

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

Hello there!

I have a problem with my device. If i reset it after it has lost focus (fullscreen) i run into a problem with reseting the device. I have to following:
[code]

void Device::ResetDevice(bool callLost)
{
HRESULT hRes;
if(callLost)
OnDeviceLost.Invoke();
DBG_CALL(m_device->Reset(&m_params));
OnDeviceReset.Invoke();
}


void Device::RenderFrame()
{
if(!m_device)
return;

m_device->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, m_backgColor, 1.0f, 0);
m_device->BeginScene();

m_device->EndScene();
HRESULT ret = m_device->Present(NULL, NULL, NULL, NULL);
if(FAILED(ret))
{
ret = m_device->TestCooperativeLevel();

// Device lost -> Fullscreen window has lost focus (alt + tab, ctrl + alt + del, ...). Lets wait until we regain focus
if(ret == D3DERR_DEVICELOST)
{
if(!m_inLostState)
{
m_inLostState = true;
OnDeviceLost.Invoke();
}
Sleep(100);
return;
}

// Device not reset -> We have regained focus and the device needs to be recreated
if(ret == D3DERR_DEVICENOTRESET)
{
m_inLostState = false;
ResetDevice(false);
return;
}
}
}
[/code]

And the rendertarget has the following code:
[code]

void RenderTarget::OnDeviceLost()
{
m_texture->Release();
}

void RenderTarget::OnDeviceReset()
{
CreateSurface();
}

bool RenderTarget::CreateSurface()
{
HRESULT hRes = m_device.GetDirectXDevice()->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET, m_device.GetBackBufferFormat(), D3DPOOL_DEFAULT, &m_texture, NULL);
if(FAILED(hRes))
return false;

m_texture->GetSurfaceLevel(0, &m_surface);
hRes = m_device.GetDirectXDevice()->CreateRenderTarget(m_width, m_height, m_device.GetBackBufferFormat(), D3DMULTISAMPLE_NONE, 0, FALSE, &m_surface, NULL);
return SUCCEEDED(hRes);
}
[/code]

OnDeviceLost is called and the texture is also recreated when the device is reset but though IDirect3DDevice9::Reset returns an invalid call. Without the render target everything works just fine. What is the problem with that?


And another question:
At the moment im calling OnDeviceLost as soon as i recognize that the device is lost. Is that correct or should i rather call it right before Reset?

Greetings and thanks
Plerion


Share this post


Link to post
Share on other sites
No, it will not. You are responsible for releasing every reference you hold. Check the documentation for all your calls to see when the reference count is increased. [url="http://msdn.microsoft.com/en-us/library/bb205912(VS.85).aspx"]GetSurfaceLevel[/url] states the following:
[quote]Calling this method will increase the internal reference count on the IDirect3DSurface9 interface. Failure to call IUnknown::Release when finished using this IDirect3DSurface9 interface results in a memory leak.[/quote]

Enable the debug runtimes in the DirectX control panel that comes with the SDK, set the debug output to max, and run with the debugger. This should give you debug messages that tell you exactly why your device fails to Reset.

Share this post


Link to post
Share on other sites

This topic is 2495 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this