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

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
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

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

Post 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?
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

re:

Post by Conquistador »

Only render the window if the window is active, look here: http://irrlicht.sourceforge.net/docu/cl ... e.html#a12
Guest

Post by Guest »

I'm already doing that
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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.
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

re:

Post 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)?
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post by Rabid Mantis »

if i alt tab out, i only get the error when I try to return to the program.
Guest

Post 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.
Rabid Mantis
Posts: 61
Joined: Sun May 08, 2005 11:30 am

Post 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.
Post Reply