I don't know if this is a bug or if there is some strange reason why this behaviour would be expected, but it seems that calling driver->getTexture() also calls my event receivers onEvent().
It gave me an access violation because my onEvent() references variables that have not yet been initialized.
I'm pretty sure this is what is happening because when I set a breakpoint right after getTexture it crashes before it gets there with an access violation in onEvent, and the callstack points right to where driver->getTexture() is called.
I'm using irrlicht 1.4.1 and visual studio 2008
getTexture calls OnEvent
when you say check a pointer do you mean checking a pointer and reporting an error if it isn't valid?
I'd rather not check every pointer everytime I want to use it, surely it's better to make sure it is only accessed after it is initialized and having a better understanding of the programs flow.
if I have an invalid pointer I think I would have to debug something anyway and skipping a chunk of code doesn't help.
plus its easier to read
I'd rather not check every pointer everytime I want to use it, surely it's better to make sure it is only accessed after it is initialized and having a better understanding of the programs flow.
if I have an invalid pointer I think I would have to debug something anyway and skipping a chunk of code doesn't help.
plus its easier to read
You don't need to display a message, you just need to avoid using the pointer that isn't valid.
It sounds like your code is something like this...
If the Device pointer isn't checked inside of the event receiver, it will still be NULL when MyEventReceiver::OnEvent() is called. That pointer won't be valid until after the call to createDevice() has completed. One way around this is to check the pointer before you use it. Another way is to avoid registering your event receiver until after the system is fully initialized.
BTW, if you're not checking pointers because it makes your code easier to read, you're just asking for trouble.
Travis
It sounds like your code is something like this...
Code: Select all
// the global Irrlicht device (bad idea to begin with)
IrrlichtDevice* Device = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent (const SEvent& event)
{
Device->getTimer ();
}
};
int main ()
{
MyEventReceiver receiver;
Device = createDevice (video::EDT_SOFTWARE, core::dimension2di(640, 480), 16, false, false, false, &receiver);
Device->drop ();
Device = 0;
}
BTW, if you're not checking pointers because it makes your code easier to read, you're just asking for trouble.
Travis