Page 1 of 1

Access Violation for run->()

Posted: Thu Jul 08, 2004 11:41 pm
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

Posted: Fri Jul 09, 2004 2:12 am
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

Posted: Fri Jul 09, 2004 4:52 am
by Guest
Alrighty:

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

Posted: Fri Jul 09, 2004 7:19 am
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()

Posted: Fri Jul 09, 2004 8:00 am
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.

Posted: Fri Jul 09, 2004 11:13 am
by warui
Can you post whole initIrrlicht() function, or even better whole class ?
And remeber to put it into

Code: Select all

 tags.

Posted: Sat Jul 10, 2004 1:34 am
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.

Posted: Sat Jul 10, 2004 1:50 am
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);

Posted: Sat Jul 10, 2004 2:05 am
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

Posted: Sat Jul 10, 2004 2:30 am
by Guest
Woot, thanks you very much for that information, it's working now :)