Page 1 of 1

System.NullReferenceException error when I alt-tab and back.

Posted: Tue Nov 08, 2005 8:18 pm
by Rabid Mantis
I get the System.NullReferenceException error when I alt-tab and come back to my program. It always points to this line:

driver->draw2DImage(backgroundimage, core::position2d<s32>(0,0),core::rect<s32>(0,0,1024,768), 0,video::SColor(255,255,255,255), true);

Either its having trouble accessing driver or backgroundimage at the moment i try to return to the program, but otherwise I don't have this problem if I don't alt-tab out. Any idea how i might fix it?

re:

Posted: Tue Nov 08, 2005 10:25 pm
by Conquistador
Only render the window if the window is active, look here: http://irrlicht.sourceforge.net/docu/cl ... e.html#a12

Posted: Wed Nov 09, 2005 12:54 am
by Guest
I'm already doing that

Posted: Wed Nov 09, 2005 12:58 am
by Rabid Mantis
oops. that was me. forgot to log in.

Yeah i'm already doing that. I'll check to make sure i didnt accidentally code outside the loop, but I don't think thats the problem. I even put
if (device->isWindowActive()) directly before the line it was crashing on and it still gave the error.

re:

Posted: Wed Nov 09, 2005 1:35 am
by Conquistador
I got no more ideas, the only thing I can think of is that the pointer to the image is invalid, which doesn't make sense since the image shows up unless you ALT+TAB, is it only happening when you ALT+TAB, or does it happen any time when your window's not active (ea. minimized)?

Posted: Wed Nov 09, 2005 3:55 am
by Rabid Mantis
if i alt tab out, i only get the error when I try to return to the program.

Posted: Wed Nov 09, 2005 6:11 am
by Guest
How (where) have you loaded the "Background" image in the first place?

Check it has not been destroyed/lost when you loose the device (alt tab), which it sounds like it has. Basically it is trying to draw an texture that has been released somehow and is now NULL rather than a valid pointer.

Posted: Wed Nov 09, 2005 7:53 am
by Rabid Mantis
I fixed it by changing my main loop to

while(Device->run() && driver)
{
if (Device->isWindowActive() && backgroundimage)


so I just have to make sure backgroundimage always has something in it.