smgr->drawAll() causes illegal operation

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!
tkarkkainen
Posts: 6
Joined: Sun Nov 21, 2004 8:50 am
Location: Finland

smgr->drawAll() causes illegal operation

Post by tkarkkainen »

I have a class called CGame. In its header file I have this among other stuff under private

Code: Select all

scene::ISceneManager *smgr;
And in the actual code I have stuff like

Code: Select all

device = createDevice ( video::EDT_OPENGL, core::dimension2d<s32>( 800, 600 ), 16, false, false, true, this );
printf ( "Device created [SUCCESS]\n" );
driver = device->getVideoDriver();
smgr = device->getSceneManager();
and later

Code: Select all

while ( device->run() )
{
   driver->beginScene( true, true, video::SColor ( 0, 100, 100, 100) );
   smgr->drawAll();
   driver->endScene();
}
device->drop();
According to the tutorials this should work. The program compiles without any errors or warnigns, but when I run the program and it reaches smgr->drawAll() Windows complains about an illegal operation. Is there anything that could cause this?

I use WinXP Pro SP1, Irrlicht 0.7 and Dev-C++ 4.9.8.0.
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Wrong lib file, include files or the dll. Make sure those are correct. Also check if your smgr pointer doesn't get redefined somewhere before the draw loop.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
tkarkkainen
Posts: 6
Joined: Sun Nov 21, 2004 8:50 am
Location: Finland

Post by tkarkkainen »

Thanks for the reply.

I checked include and lib directories. Include directory is irrlicht-0.7\include\ and lib irrlicht-0.7\lib\DevCpp which should be correct. Also, the dll is correct.smgr pointer doesn't get redefined.

Anything else I could check?
T101
Posts: 44
Joined: Thu Jul 29, 2004 4:41 pm

Post by T101 »

device = createDevice ( video::EDT_OPENGL, core::dimension2d<s32>( 800, 600 ), 16, false, false, true, this );
Is that in the event receiver?
tkarkkainen
Posts: 6
Joined: Sun Nov 21, 2004 8:50 am
Location: Finland

Post by tkarkkainen »

Sorry for the long silence.

T101: that line is in a class that is inherited from irr::IEventReceiver. Hopefully this bit of information helps.

I've really been pulling my hair out with this problem.
Guest

Post by Guest »

According to the docu, drawAll must be called between BeginScene and EndScene - you've written that correctly.

But maybe BeginScene fails? You might want to check the return value of BeginScene: false if it fails.
Although I have no idea why it should fail.
Guest

Post by Guest »

And looking a bit further:
when you call BeginScene with true,true, you're asking the driver to clear the backbuffer - I'm not sure you're guaranteed to get a backbuffer with OpenGL when you're running windowed. Maybe that's what's causing the error?
Guest

Post by Guest »

Well, BeginScene doesn't fail. I added a row after it and it got executed (it printed "blah") and after that the illegal operation got thrown.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

It doesn't notify you of failing by ending the program. It fails by returning a false value. It's up to you to check that value and act on it. The fact that the print out worked after that call means nothing.

I'd bet you have a mismatch with your DLL and LIB files.
Guest

Post by Guest »

but you also declare your device, driver, and scene manager under private. would this have any effect? what would happen if it were public?
tkarkkainen
Posts: 6
Joined: Sun Nov 21, 2004 8:50 am
Location: Finland

Post by tkarkkainen »

Code: Select all

       if ( ! driver->beginScene( true, true, video::SColor ( 0, 100, 100, 100) ) )
              printf ( "CATASTROPHIC FAILURE!" );
       smgr->drawAll();
       driver->endScene();
I tried this and it makes no difference. The program doesn't output catastrophic failure, but the problem still remains.

I'm using the Dev-C++ lib directories and the Dev-C++ DLL from Irrlicht 0.7. That shouldn't be a mismatch, right?

And finally, declaring device, driver and scene manager under public didn't help.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

To see if the device is actually being created, check it before continuing like so :

Code: Select all

device = 0;
device = createDevice ( video::EDT_OPENGL, core::dimension2d<s32>( 800, 600 ), 16, false, false, true, this ); 

if ( !device )
{
  printf ( "Failed to create device!\n" );
  return -1;
}

printf ( "Device created [SUCCESS]\n" ); 
driver = device->getVideoDriver(); 
smgr = device->getSceneManager(); 
Also, try changing your create device call to -

Code: Select all

device = createDevice ( video::EDT_OPENGL, core::dimension2d<s32>( 800, 600 ), 16, false, false, false, this ); 
This will turn off vsync, maybe this is your problem.
tkarkkainen
Posts: 6
Joined: Sun Nov 21, 2004 8:50 am
Location: Finland

Post by tkarkkainen »

I tried both. Didn't help but thanks for trying.
Guest

Post by Guest »

Did you at least try this:

device = createDevice ( video::EDT_OPENGL, core::dimension2d<s32>( 800, 600 ), 16, true, false, true, this );

That would create a full-screen session - which pretty mch guarantees that there's going to be a backbuffer to clear.

If it doesn't fail in that case, the problem is indeed in clearing the backbuffer - although I don't know why it would fail AFTER the clear.
tkarkkainen
Posts: 6
Joined: Sun Nov 21, 2004 8:50 am
Location: Finland

Post by tkarkkainen »

Yes, I indeed did try that.
Post Reply