Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2496
  • Last Modified:

How to recover from device lost?

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
UdiRaz
Asked:
UdiRaz
  • 6
  • 5
1 Solution
 
jgordosCommented:
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
 
UdiRazAuthor Commented:
what do you mean by stack space?
0
 
jgordosCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
UdiRazAuthor Commented:
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
 
jgordosCommented:
no, the stack for the executable... the C++ program.

In other words, how did you declare  m_pp?
0
 
UdiRazAuthor Commented:
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
 
jgordosCommented:
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
 
UdiRazAuthor Commented:
Thanks,

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

Udi
0
 
UdiRazAuthor Commented:
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
 
jgordosCommented:
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now