Access Violation

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
crosel
Posts: 11
Joined: Fri May 29, 2009 6:53 am

Access Violation

Post by crosel »

Ok, im trying to create a chat system that runs concurrently with the irrlicht engine. So i can have a game and chat system at the same time.

To do both, ive got a nested loop (probably a bad thing).

Code: Select all

while(GetMessage(&msg,NULL,0,0))
{
	TranslateMessage(&msg);
	DispatchMessage(&msg);

	//Run the game, simple draw/update loop.
	game->Run();
}
The definition of Run() is this:

Code: Select all

void Game::Run()
{
	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	device->drop();
}
The issue is, when i close the program, i get an access violation at this line

Code: Select all

while(device->run())
Im guessing its because its trying to run the device, yet its been dropped.

Any suggestions on what i can do to stop it from crashing[/code]
Xarshi
Posts: 27
Joined: Sat Feb 28, 2009 6:15 pm

Post by Xarshi »

Code: Select all

while(GetMessage(&msg,NULL,0,0))
{
   TranslateMessage(&msg);
   DispatchMessage(&msg);

   //Run the game, simple draw/update loop.
   game->Run();
} 
That code seems redundant. Why not just have your loop like:

Code: Select all

while (game->Run())
{
   game->Update();
}
Of course, you'd have to change your methods a little like for Run, it would be basically just calling and returning the IrrlichtDevice::run() method and result. Then Game::Update you would have this code:

Code: Select all

driver->beginScene(true, true, SColor(255,100,101,140));

 smgr->drawAll();
guienv->drawAll();

driver->endScene();
Anyways, I'm 99% sure Irrlicht already calls TranslateMessage and DispatchMessage on its own. Try the way I suggested, it will most likely work. I'd probably just not have a Game::Run and just call the IrrlichtDevice::run method directly. But that's just me.
Post Reply