Access Violation for run->()

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
Guest

Access Violation for run->()

Post by Guest »

Hi,

I have a CIrrlichtManager class that has a function initIrrlicht which creates a device with the same code (with OPENGL instead of software) in the hellworld tutorial, so that is not the problem. In my main.cpp I create an instance of my CIrrlichtManager class like so:

CIrrlichtManager irrlichtManager;

Then I call the initIrrlicht function like so:

irrlichtManager.initIrrlicht();

I then check to see if the device is null (to see if that was the problem, but it isnt).

Then I do this (the line where the program errors after debugging with msvc++ 2003)

while(irrlichtManager.device->run()) //Error line
{
irrlichtManager.driver->beginScene(true, true, Scolor(0,100,100,100));
irrlichtManager.smgr->drawAll();
irrlichtManager.guienv->drawAll();

irrlichtManager.driver->endScene();
}

It all compiles fine but when I run it, the program crashes and I when I debug it in MSVC++ 2003 it errors on the while loop for run->() with this error:


Unhandled exception at 0X003d004a in OninWars.exe: OxC0000005: Access violation writing location 0x0016f03d

Thanks for any help
Mindl
Posts: 16
Joined: Wed Jun 30, 2004 1:42 am

Post by Mindl »

What are you initializing your device as? Just like the tutorial but with EDT_OPENGL ? Maybe post the initialization code for us.

-Mindl
Guest

Post by Guest »

Alrighty:

IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 32, true, false, 0);
Guest

Post by Guest »

when you got a pointer don't try to access the device like you did.
you probably need to do something like this :

irrlichtManager->device->run()
Guest

Post by Guest »

That gave me an error, saying I should use "." instead, because left of -> doesn't point to a class/struct/union, I think . is right.
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

Can you post whole initIrrlicht() function, or even better whole class ?
And remeber to put it into

Code: Select all

 tags.
Tomasz Nowakowski
Openoko - www.openoko.pl
Guest

Post by Guest »

Sure,

Code: Select all

void CIrrlichtManager::initIrrlicht()
{
IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(800,600), 32, true, false, 0);

IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();

ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 30, 50, -1);
}
Unfortunatley, I had to type that out instead of copy and paste because I'm on another computer, lol.
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

By calling like that:

Code: Select all

IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(800,600), 32, true, false, 0);
You create a new pointer which is deleted as soon as program leaves functions body.

If you want to assign a new value to device, member of your class it should be:

Code: Select all

device = createDevice(EDT_OPENGL, dimension2d<s32>(800,600), 32, true, false, 0);
Tomasz Nowakowski
Openoko - www.openoko.pl
Mindl
Posts: 16
Joined: Wed Jun 30, 2004 1:42 am

Post by Mindl »

You should make "device" a public variable of the CIrrlichtManager class by declaring it in the public section of the class definition.

Code: Select all

 
public:
         IrrlichtDevice *device;
Then you use as warui said

Code: Select all

 device = createDevice(EDT_OPENGL, dimension2d<s32>(800,600), 32, true, false, 0);
In the initilization function. You can do the same for the other stuff to like SceneManager and what not.

-Mindl
Guest

Post by Guest »

Woot, thanks you very much for that information, it's working now :)
Post Reply