run method immediatly returns false for second IrrlichtDevic

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Pouf
Posts: 6
Joined: Fri Feb 27, 2015 11:37 pm

run method immediatly returns false for second IrrlichtDevic

Post by Pouf »

Hi,

I'd like to create a second IrrlichtDevice after closing and droping a first one. Something like this :

Code: Select all

 
IrrlichtDevice * poDevice = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32, false, true, false);
 
while(poDevice->run())
{
    // ...
}
 
poDevice->closeDevice();
poDevice->drop();
 
// Creating a new device
poDevice = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32, false, true, false);
 
while(poDevice->run())
{
    // ...
}
 
poDevice->closeDevice();
poDevice->drop();
 
I know this has little interest as it is, but it's just a simple way to show you where's my problem. In fact, I load a Irrlicht based library, which create a device, and I'd like to be able to unload it, and reload it later, with it creating a new device.

Yet, when I do, the device is created, but the run method directly returns false :

Code: Select all

 
// Load my Irrlicht-based library
// Instanciate my Irrlicht class which creates a device
mpoDevice = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32, false, true, false, this);
 
// ...
 
// Delete my instance which closes and drops the device
mpoDevice->closeDevice();
mpoDevice->drop();
 
// Unload my Irrlicht-based library
 
// ...
 
// Reload my Irrlicht-based library
// Re-instanciate my Irrlicht class which re-creates a device
mpoDevice = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32, false, true, false, this);
 
// Run the device
while(mpoDevice->run()) // This returns immediatly false, thus my device never renders anything
    // ...
 
// etc...
 
(The goal is to be able to switch between several interfaces, such as Console, SDL, Irrlicht, etc... in my game. Everything works perfectly, but this).

Thank you.
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

Re: run method immediatly returns false for second IrrlichtD

Post by pandoragami »

AFAIK Irrlicht is single threaded so that might be a problem or reason for this, not 100% positive though.
Pouf
Posts: 6
Joined: Fri Feb 27, 2015 11:37 pm

Re: run method immediatly returns false for second IrrlichtD

Post by Pouf »

I don't see why that could cause any problem. All I do is sequencial, single threaded too.
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

Re: run method immediatly returns false for second IrrlichtD

Post by pandoragami »

Pouf wrote:I don't see why that could cause any problem. All I do is sequencial, single threaded too.
Right, it should work after you create the second device since you drop the first one but it doesn't.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: run method immediatly returns false for second IrrlichtD

Post by mongoose7 »

It looks to me as if the first close sets the variable 'Close' to true, but this variable is not set to false by the createDevice. I don't even know where this variable is supposed to be; there is one in irrXML.cpp, is this it?
Pouf
Posts: 6
Joined: Fri Feb 27, 2015 11:37 pm

Re: run method immediatly returns false for second IrrlichtD

Post by Pouf »

Indeed, it's a 'Close' variable defined in CIrrDeviceStub.h, put to false in CIrrDeviceWin32.cpp in the closeDevice method, and not reinitialized by the createDevice method. But I'm really surprised that it's not even after unloading and reloading my library... It looks like Windows keep my first memory content, and just restores it for my second load :/

Edit : There's a default value for Close in the CIrrDeviceStub constructor.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: run method immediatly returns false for second IrrlichtD

Post by CuteAlien »

I do not think this has to do with a Close variable. You create a new object with createDevice - so any variables in your old object have nothing to do with this. Depending on how the rest of the code looks which you didn't post it might be that you get system messages here. Like a close send to the old device which is only arriving when the new device is created. So you might need a call to clearSystemMessages () for the new device as first call. If that isn't it we need an example which allows to reproduce the problem.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: run method immediatly returns false for second IrrlichtD

Post by greenya »

As far i know when you call closeDevice() you need to call run() and then drop() the device. Because closeDevice() can be called anywhere, and the run() is responsible to handle the closing and returning false.
Post Reply