Page 1 of 1

WHY? Stupid problem... why is it doing this?

Posted: Fri Oct 14, 2005 11:14 am
by Rabid Mantis
I'm having a problem with a certain line whenever I try to load a model.

scene::IAnimatedMesh* m = Device->getSceneManager()->getMesh(filename);

If I have this line in main() it works. But if I for example put it in LoadModel() and call it from that exact same place, it gives me the System.NullReferenceException error.

I have Device declared as a global
IrrlichtDevice *Device = 0;
and then set it up at the beginning of main()
IrrlichtDevice *Device = createDevice(video::EDT_DIRECTX9,
core::dimension2d<s32>(1024, 768),
16, true, false, false, &receiver);


Does anyone know what could be happening? I've done this exact same thing in other programs without getting this problem.

Posted: Fri Oct 14, 2005 12:12 pm
by MasterD
When you set your Device in Main with

IrrlichtDevice * Device ...

a new local Variable is being created which has nothing in commen with your global pointer (except for same variable types).

only use

Device = ...

Posted: Fri Oct 14, 2005 2:18 pm
by WToma
Or pass your Device to LoadModel as a parameter.
Toma

Posted: Fri Oct 14, 2005 7:27 pm
by Rabid Mantis
oh crap, you're right. how could I have missed that? :oops: i guess thats what i get for copy/pasting code without double checking it.

I am the village idiot.