Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to recover from device lost?

Posted on 2008-10-07
12
Medium Priority
?
2,473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 

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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

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