Page 1 of 1

Access Violation

Posted: Wed Sep 30, 2009 11:50 am
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]

Posted: Wed Sep 30, 2009 12:28 pm
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.