[Help] Reset Device

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Insects
Posts: 7
Joined: Thu Oct 25, 2007 1:58 am

[Help] Reset Device

Post by Insects »

Hi,

I have an application which allow to change the device properties and reset it.

The properties are : AntiAlias, Bits, DriverType, Fullscreen, Stencilbuffer, Vsync, WindowSize.

Here is a sample of code to reset the device :

Code: Select all

	if (device)
	{
		device->closeDevice();
		device->run();
		device->drop();
		device = NULL;
	}

	device = createDeviceEx(deviceParam);

	videoDriver = device->getVideoDriver();
My problem is that sometimes it works sometimes it doesn't..

In fact, if I play a little (changing..resetting..changing..resetting..) then sometimes i get a crash on "device->getVideoDriver();" meanings that the "createDeviceEx" failed.

Does anyone have an idea about this random crash ?

Thanks a lot ;)
++

PS: here is the console output after the crash :

Code: Select all

Was not able to create Direct3D9 device.
Was not able to create DIRECT3D9 device.
Could not create DIRECT3D9 Driver.
kingdutch
Posts: 76
Joined: Tue Sep 02, 2008 7:01 am

Post by kingdutch »

You gave us the code where the problem most likely is, however it's a bit out of context so atleast I can't do anything with it.

The createDeviceEx function is not an Irrlicht one is it? Could you post it?

Also, I don't understand why there's a device->run(); after device->closeDevice(); since it'll just return false from what I've read.

Furthermore, I don't know what parameters you are passing to the createDeviceEx function so I don't know what's causing the problem

Kingdutch
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

createDeviceEx is the Irrlicht device creation with extended parameter set. The device->run is required under Windows to make sure all close events are consumed, other wise the device might close immediately due to old close messages in the queue.
Please post a complete code which can reproduce the behavior. Since these issues can also be related to the hw drivers and your system please also post all information available about your gfx system. Which drivers do you use, does it happen with all Irrlicht drivers, did you try older or newer hw drivers?
Insects
Posts: 7
Joined: Thu Oct 25, 2007 1:58 am

Post by Insects »

Well hybrid is completely right, for more informations about createDeviceEx :
http://irrlicht.sourceforge.net/docu/na ... .html#a179

About the issues as i said the output is :

Code: Select all

Was not able to create Direct3D9 device. 
Was not able to create DIRECT3D9 device. 
Could not create DIRECT3D9 Driver.
which refers to CD3D9Driver.cpp line 359 :

Code: Select all

hr = pID3D->CreateDevice(D3DADAPTER_DEFAULT, devtype, hwnd,
				fpuPrecision | D3DCREATE_HARDWARE_VERTEXPROCESSING, &present, &pID3DDevice);

		if(FAILED(hr))
			hr = pID3D->CreateDevice(D3DADAPTER_DEFAULT, devtype, hwnd,
					fpuPrecision | D3DCREATE_MIXED_VERTEXPROCESSING , &present, &pID3DDevice);

		if(FAILED(hr))
			hr = pID3D->CreateDevice(D3DADAPTER_DEFAULT, devtype, hwnd,
					fpuPrecision | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present, &pID3DDevice);

		if (FAILED(hr))
			os::Printer::log("Was not able to create Direct3D9 device.", ELL_ERROR);
	}

	if (!pID3DDevice)
	{
		os::Printer::log("Was not able to create DIRECT3D9 device.", ELL_ERROR);
		return false;
	}
I've tried a lot of combinations and here is finally the behavior which produce the crash :
  • - only happen with directx (both Direct3D 8.1 and Direct3D 9)
    - only in fullscreen
    - and finally, only in 1280x800 (which is my highest resolution)
About the code :

Code: Select all

while (still_running)
{
	engine_graphic->update();
}

Code: Select all

CENGINEGraphic::CENGINEGraphic()
{
	// Initializes
	SIrrlichtCreationParameters param;
	param.AntiAlias = false;
	param.Bits = 32;
	param.DriverType = EDT_DIRECT3D9;
	param.Fullscreen = true;
	param.Stencilbuffer = false;
	param.Vsync = false;
	param.WindowSize = dimension2d<s32>(1280, 800);
	
	initEngine(param);
}
	
void CENGINEGraphic::initEngine(SIrrlichtCreationParameters	deviceParam)
{
	try
	{
		device = createDeviceEx(deviceParam);

		// Gets video driver
		videoDriver = device->getVideoDriver();

		// Gets scene manager
		sceneManager = device->getSceneManager();
		
		// Gets gui environment
		guiEnv = device->getGUIEnvironment();
	}
	catch (exception &e)
	{
		cerr << e.what() << endl;
    }

	reset_engine = false;
}

void CENGINEGraphic::resetEngine()
{
	// Clear
	videoDriver->removeAllTextures();
	guiEnv->clear();
	sceneManager->clear();
	
	videoDriver->drop();
	videoDriver = NULL;
	guiEnv = NULL;
	sceneManager = NULL;

	// Closes the device
	if (device)
	{
		device->setEventReceiver(NULL);
		device->closeDevice();
		device->run();
		device->drop();
		device = NULL;
	}

	// Re-inits the engine
	initEngine(getNewDeviceParam());
}

void CENGINEGraphic::update()
{
	if (reset_engine) 
		resetEngine();
	else
	{	
		if (!videoDriver || !device->run())
			exit();
	
		//** Render
		videoDriver->beginScene(true, true, background_color);
		sceneManager->drawAll();
		guiEnv->drawAll();
		videoDriver->endScene();
		//**
	}
}
I think the code is easy understanding. The window contain one checkbox per device property and one button to apply the changes (which simply set reset_engine to true and keep the new parameters)

Causing the crash is just to play randomly with AntiAlias, Stencilbuffer and Vsync.

My system informations :
  • - Irrlicht Engine version 1.4
    - Microsoft Windows XP Professional Service Pack 3 (Build 2600)
    - NVIDIA GeForce Go 7400 nv4_disp.dll 6.14.10.8418
    - 2046MB RAM
    - DirectX 9.0c (4.09.0000.0904)
Thanks for your help ;)
Insects
Posts: 7
Joined: Thu Oct 25, 2007 1:58 am

Post by Insects »

Well.. like i'm used to say "If you want something done, do it yourself".

Finally, after several days of debugging and test, I found out that "videoDriver->removeAllTextures()" was doing nothing.

My crash was due to one texture which was not removed (only one *$%# texture ! :twisted: ) So I removed it by my myself.

Hope this can help someone else.
Thanks anyway ;)
kingdutch
Posts: 76
Joined: Tue Sep 02, 2008 7:01 am

Post by kingdutch »

Glad to see it's fixed, sorry for my earlier post :oops:

Clearly didn't do my homework! ^^
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

Insects wrote:Finally, after several days of debugging and test, I found out that "videoDriver->removeAllTextures()" was doing nothing.

My crash was due to one texture which was not removed (only one *$%# texture ! :twisted: ) So I removed it by my myself.

are you saying that there is a bug or that you loaded a texture manually and did not release it properly?
Post Reply