Revalidating the device (DX8)

Started by
4 comments, last by vbisme 22 years ago
How do I revalidate the device when returning from alt-tab? I followed the examples from "Zen of Direct3D Game Programming." However, even their example crashes every time I return from alt-tab.
Advertisement
I can''t remember the hard and fast rules of what needs to reset after you lose a device in d3d, but looking at my code, I do the following:
+ Recreate (and lock and fill) any resources not managed by d3d (including textures, surfaces, vertexbuffers and index buffers)
+ Reset all current renderstates, lights and materials
+ Reset all the transforms e.g. D3DTS_VIEW etc..
+ And of course, reset the device with relevant presentation parameters (e.g if the window size has changed, you''ll need a different sized back-buffer etc..).

Like I said, I can''t remember if its neccesary to reset the lights and materials, so the best way is to try.. I kinda learnt this the hard way (the docs are a bit disjointed in this area), and now I have a set of resource classes that do all that stuff for me so i''ve forgotten all the rules...

Hope that helps a bit..

T
You have to:

release all video memory you have allocated, including target rendering surfaces, stencil surfaces, swap chains, anything you declare w/ D3DPOOL_DEFAULT (stuff in system memory or declared w/ D3DPOOL_MANAGED is ok)

check to see whether you can reset the device using TestCooperativeLevel

call Reset

set everything back up
If you specify a transparent color key when loading a texture into a D3DPOOL_MANAGED texture I''ve noticed on some machines that after the device has been reset, the color that was origionally transparent will be rendered as opaque black.
the code that is use(that doesn''t work) is:


  if (!cdp_D3DDevice)	{		return(1);	}//end if	cd_hResult = cdp_D3DDevice->TestCooperativeLevel();	//check device state	if (FAILED(cd_hResult))	{		switch (cd_hResult)		{		case D3DERR_DEVICELOST:	//device is lost, nothing we can do			{				//MessageBox(cd_WinHandle, "Device is lost!", "CheckDevice", MB_OK);				return (1);			}break;		case D3DERR_DEVICENOTRESET:	//if device is ready to be reset			{				cdp_BackBuffer->Release();	//release the backbuffer				cd_hResult = cdp_D3DDevice->Reset(&cd_D3Dpp);	//reset with the saved present parameters				if (FAILED(cd_hResult))				{					MessageBox(cd_WinHandle, "Cannot reset device!", "CheckDevice", MB_OK);					PostQuitMessage(E_FAIL);	//cannot reset, quit				}//end if				//--Try to get a new backbuffer--//				cd_hResult = cdp_D3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &cdp_BackBuffer);				if (FAILED(cd_hResult))				{					PostQuitMessage(E_FAIL);				}//end if				//--//				ClearScreen(255, 0, 0, 0);			}		}//end switch	}//end if  


Can someone show me some examples?
vbisme

- I''m assuming you''re drawing things too (which isn''t listed).

The general rule of thumb is that anything you''ve created using cdp_D3DDevice needs to be released and reaquired when you''ve lost the device (at least before you try using it again).

For instance, if you''re using a vertex buffer to draw, you need to do a ->Release() on it and then recreate it before the next use.

My guess is, check your ClearScreen() function. It''s probably using something from the old device.


TLC

This topic is closed to new replies.

Advertisement