run() in new devices always returns false

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
TDragon
Posts: 4
Joined: Tue May 04, 2004 11:06 pm
Location: Colorado, USA
Contact:

run() in new devices always returns false

Post by TDragon »

I discovered this in trying to create a program that does something similar to the Techdemo: a menu using one device, then the main program using a new device. I found out that device->run() in the main program always returns false, even though I'd created it and it appeared to be working fine. Here's some sample code that I created and compiled which always does that for me:

Code: Select all

#include <cstdio>
#include <irrlicht.h>

using namespace irr;

class MyClass : public IEventReceiver
 {
public:
  void run(void);
  IrrlichtDevice * idevice;
  virtual bool OnEvent(SEvent event);
  MyClass();
  virtual ~MyClass();
 };

MyClass::MyClass()
 {
  idevice = NULL;
 }

MyClass::~MyClass()
 {
  if (idevice)
   {
    idevice->closeDevice();
    idevice->drop();
   }
 }

void MyClass::run(void)
 {
  //IrrlichtDevice* createDevice  (  video::EDriverType    deviceType = video::EDT_SOFTWARE,  
  //const core::dimension2d< s32 > &    windowSize = core::dimension2d< s32 >(640, 480),  
  //u32    bits = 16,  
  //bool    fullscreen = false,  
  //bool    stencilbuffer = false,  
  //IEventReceiver *    receiver = 0,  
  //const wchar_t *    sdk_version_do_not_use = IRRLICHT_SDK_VERSION 
  //)

///// First device
  idevice = createDevice(video::EDT_SOFTWARE, core::dimension2d<s32>(640, 480), 16, false, false,
   this);
  if (!idevice)
   {
    printf("\nCouldn't create first Irrlicht device.\n\n");
    return;
   }
  if (!idevice->run())
   {
    printf("\nFirst device can't run.\n\n");
    idevice->closeDevice();
    idevice->drop();
    return;
   }
  idevice->closeDevice();
  idevice->drop();
  idevice = NULL;

///// Second device
  idevice = createDevice(video::EDT_DIRECTX8, core::dimension2d<s32>(640, 480), 16, false, false,
   this);
  if (!idevice)
   {
    printf("\nCouldn't create second Irrlicht device.\n\n");
    return;
   }
  if (!idevice->run())
   {
    printf("\nSecond device can't run.\n\n");
    idevice->closeDevice();
    idevice->drop();
    return;
   }
  idevice->closeDevice();
  idevice->drop();
  printf("Run successful.\n");
  return;
 }

bool MyClass::OnEvent(SEvent event)
 {
  return false;
 }

int main(int argc, char * argv[])
 {
  
  printf("Creating class\n");
  MyClass * mc = new MyClass;
  printf("Running class\n");
  mc->run();
  printf("Deleting class\n");
  delete mc;

  return 0;
 }
When running that program, I always get this output:

Code: Select all

Creating class
Running class
Irrlicht Engine version 0.5
Microsoft Windows 98 SE
Irrlicht Software Renderer.
Loaded texture: #DefaultFont
Irrlicht Engine version 0.5
Microsoft Windows 98 SE
DirectX8 Renderer.
Loaded texture: #DefaultFont

Second device can't run.

Deleting class
Is this something to do with my pc, or is it truly an Irrlicht bug? I can't tell...

And, is there a workaround?

Oh, and -- the reason I'm using Irrlicht 0.5 is that when I use DirectX devices in Irrlicht 0.6, there's a terrible amount of screen flickering, which isn't the case in Irrlicht 0.5. That may or may not be a bug, but I tend to think it has to do with my graphics card which is a low end (8mb) onboard video card.
{) Twilight Dragon (}
{) tdragon.tk (}
TDragon
Posts: 4
Joined: Tue May 04, 2004 11:06 pm
Location: Colorado, USA
Contact:

Post by TDragon »

Um, does anybody have any idea at all? Please? Like, will calling device->run() work properly even if it's returning false? Or what can I do?
{) Twilight Dragon (}
{) tdragon.tk (}
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Maybe this is a bug I corrected, try to switch to Irrlicht 0.6
ahe
Posts: 2
Joined: Sun Jun 13, 2004 10:16 am

Post by ahe »

I also ran into this problem a few days ago when working in windows.
I dont have the code in front of me atm, but I think
I figured out that run() will have to be called once
after ->closeDevice() in order to flush the message buffer
or whatever run() is doing with those PeekMessage and stuff.

I could get it solved by doing

device = createDevice(....);

device->run();

device->closeDevice();
device->run(); // Think this flush the message buffer..
device->drop();

device = createDevice(....)
DrBenito
Posts: 35
Joined: Mon Jul 19, 2004 8:50 pm
Location: Newcastle, UK
Contact:

Post by DrBenito »

I too stumbled on this problem today. same findings here, the first call to device->run() always seems to return false for any new devices created.

Code: Select all

int main(int argc, char *argv[])
{
  
  IrrlichtDevice * deviceOne;
  IrrlichtDevice * deviceTwo;
  
  //Create, run and close device one
  
  deviceOne = createDevice();
  int countOne = 0;
  while( deviceOne->run() )
  {
    ++countOne;
    
    if( countOne > 10000 ) break;
  }  
  deviceOne->closeDevice();
  cout << "countOne after deviceOne closed = " << countOne << endl;
  
  //Creare, run and close device two
  deviceTwo = createDevice();
  int countTwo = 0;
  
  // On first test, leave this line commented and note the 
  //   countOne and countTwo values.
  // On second test, uncomment this line and again note the values.
  
  // deviceTwo->run(); // Test Line (uncomment for 2nd test)
  
  while( deviceTwo->run() )
  {
    ++countTwo;
    
    if( countTwo > 10000 ) break;
  }  
  deviceTwo->closeDevice();
  cout << "countTwo after deviceTwo closed = " << countTwo << endl;
  
  
  system("PAUSE");	
  return 0;
}
The workaround I'll be using is uncommenting my line in the above code before going into the while(device->run()) loop.

Haven't had a chance to have a poke around in the Irrlicht code yet, was just wondering if others had found this problem and whether there was another fix/workaround.

Cheers
Ben
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

Wow. Niko (or anyone) can you please explain why 2 IrrlichtDevices are used in the TechDemo. I didnt realise it was like that.
-Thanks
"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

How would you switch between Software and DirectX/OpenGL ?
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Post Reply