Advertisement

10.07.2008 at 08:15AM PDT, ID: 23794038
[x]
Attachment Details

How to recover from device lost?

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6
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

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:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
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;
}
Answered By: jgordos
Expert Since: 06/06/2005
Accepted Solutions: 114
Computer Expertise: Guru
Education: Ohio University, Bachelor's Degree
jgordos has been an Expert for 3 years 7 months, during which he has posted 432 comments and answered 114 questions. jgordos is just one of 98 experts in the DirectX Graphics & Game Programming Zone. 1 expert collaborated on this answer, which was graded an "A" by the asker.
 
 
20081119-EE-VQP-48 - Hierarchy / EE_QW_2_20070628