Solved

How to recover from device lost?

Posted on 2008-10-07
12
2,426 Views
Last Modified: 2013-12-21
Hi,

below is a code snippet of a sample I found on how to recover from device lost. For some reasons
hr = m_device->Reset( &m_pp );
returns an error.
The error is not one of this methods errors (0x8876086c) so I have no clue what is wrong


if( m_bDeviceLost == true )

{

  // Yield some CPU time to other processes

  Sleep( 100 ); // 100 milliseconds
 
 

  // Test the cooperative level to see if it's okay to render.

  // The application can determine what to do on encountering a lost 

  // device by querying the return value of the TestCooperativeLevel 

  // method.

  //
 

  if( FAILED( hr = m_device->TestCooperativeLevel() ) )

  {

	// The device has been lost but cannot be reset at this time. 

	// Therefore, rendering is not possible and we'll have to return 

	// and try again at a later time.

	if( hr == D3DERR_DEVICELOST )

		return S_OK;
 

	// The device has been lost but it can be reset at this time. 

	if( hr == D3DERR_DEVICENOTRESET )

	{

		//

		// If the device can be restored, the application prepares the 

		// device by destroying all video-memory resources and any 

		// swap chains. 

		//

                  

                  // delete all Direct3D objects except IDirect3D9 and IDirect3DDevice9

		DeleteDirect3D( true );
 

		//

		// Then, the application calls the Reset method.

		//

		// Reset is the only method that has an effect when a device 

		// is lost, and is the only method by which an application can 

		// change the device from a lost to an operational state. 

		// Reset will fail unless the application releases all 

		// resources that are allocated in D3DPOOL_MANAGED, including 

		// those created by the IDirect3DDevice9::CreateRenderTarget 

		// and IDirect3DDevice9::CreateDepthStencilSurface methods.

		//
 

		hr = m_device->Reset( &m_pp );
 

		if( FAILED(hr ) )

			return S_OK;
 

		//

		// Finally, a lost device must re-create resources (including  

		// video memory resources) after it has been reset.

		//
 

		InitResources();

		//			Init(m_window, m_width, m_height, m_fontName, m_fontSizee);

		m_init = true;

		StringMap tmp = _T("");

		InitScene( true, true, tmp);

		m_init = false;
 

	}
 

	return S_OK;

  }	
 

  m_bDeviceLost = false;

}

Open in new window

0
Comment
Question by:UdiRaz
  • 6
  • 5
12 Comments
 
LVL 11

Expert Comment

by:jgordos
ID: 22673847
In this instance, you don't show where you create/initialize the variable m_pp


Is it null?

Did you give it enough stack space?

-john
0
 

Author Comment

by:UdiRaz
ID: 22683407
what do you mean by stack space?
0
 
LVL 11

Expert Comment

by:jgordos
ID: 22683523
Hmm.  

Well, when you declare a variable, it uses memory.

This memory is allocated from one of two places, depending on how you declare them: either the run-time stack, or the run-time heap.

You're passing the variable by reference, but you don't show where you allocate or declare this variable... so, it's very possible that you haven't given it space, or initialized it, or whatever, and that could be causing your problem.

-john
0
 

Author Comment

by:UdiRaz
ID: 22688901
I know what stuck is and what stuck space means, but not in Direct3D context. When I declare variables on Direct3D, I don't specify a stuck space.

Do you mean some general windows or direct3d settings where I can set a larger stack space?
or Do you mean that there is a Direct3D method that defines a stack space?

Thanks again.
Udi
0
 
LVL 11

Expert Comment

by:jgordos
ID: 22690760
no, the stack for the executable... the C++ program.

In other words, how did you declare  m_pp?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:UdiRaz
ID: 22696578
m_pp is created once. I don't create it again after the device is lost. Am I supposed to?
/******************************************************************************************

// InitPresentParameters() : Initializes PresentParameters so they can be passed to CreateDevice

//******************************************************************************************

void CDisplay::InitPresentParameters()

{
 

	//Clear out our D3DPRESENT_PARAMETERS structure.  Even though we're going

	//to set virtually all of its members, it's good practice to zero it out first.

	ZeroMemory(&m_pp,sizeof(D3DPRESENT_PARAMETERS));
 

	//Whether we're full-screen or windowed these are the same.

	m_pp.BackBufferCount= 1;  //We only need a single back buffer

	m_pp.MultiSampleType=D3DMULTISAMPLE_NONE; //No multi-sampling

	m_pp.MultiSampleQuality=0; //No multi-sampling

	m_pp.SwapEffect     = D3DSWAPEFFECT_DISCARD; // Throw away previous frames, we don't need them

	m_pp.hDeviceWindow  = m_window;  //This is our main (and only) window

	m_pp.Flags=0;  //No flags to set

	m_pp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT; //Default Refresh Rate

	m_pp.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE; //Default Presentation rate

	m_pp.BackBufferFormat  = D3DFMT_UNKNOWN; //Display format
 
 

	m_pp.EnableAutoDepthStencil=FALSE;
 

	m_pp.AutoDepthStencilFormat=D3DFMT_UNKNOWN; //This is ignored if EnableAutoDepthStencil is FALSE
 

	//BackBufferWidth/Height have to be set for full-screen applications, these values are

	//used (along with BackBufferFormat) to determine the display mode.

	//They aren't needed in windowed mode since the size of the window will be used.
 

	m_pp.Windowed          = TRUE;
 

}

Open in new window

0
 
LVL 11

Expert Comment

by:jgordos
ID: 22713720
Sorry, got busy...

the error you're getting is

   D3DERR_INVALIDCALL

Essentially, there's something that's preventing the reset of your device.

I can't tell from the code, but if you've created any surfaces and triangles, fonts, etc that use the device, you'll need to release all of those.

Do you get any messages in the DirectX logs?  Turn debugging on and retry... you'll probably be given a clue about what's making that an INVALID call.

-john
0
 

Author Comment

by:UdiRaz
ID: 22729251
Thanks,

How to turn debugging on and how to view the directx log?

Udi
0
 
LVL 11

Expert Comment

by:jgordos
ID: 22735828
0
 

Author Comment

by:UdiRaz
ID: 22752339
Here is the line that makes reset fail :

I am calling this method at the beggining of my render method.

Any idea what is the problem?


	IDirect3DSurface9* backBuffer=0;	

	m_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); // get back buffer surface

	ASSERT(backBuffer);

Open in new window

0
 
LVL 11

Accepted Solution

by:
jgordos earned 500 total points
ID: 22767247
Did you release the backbuffer before calling reset?

IE, did you call
        m_device->Release();

The Release call will also return a count of the current number of "locks" on the device...  Make sure it goes to zero before you call Reset().

-john
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now