Problem with relaunching

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
LordNyson
Posts: 31
Joined: Tue Nov 11, 2008 12:02 pm
Location: Perth, Australia

Problem with relaunching

Post by LordNyson »

Basically, I'm creating a graphics screen that will relaunch based apon graphical options changed, I am having problems with access violations everytime it tries to relaunch the engine. Basically my belief is that it does not pass correct variables to the engine when it wants to relaunch or they some how get corrupted...

Code: Select all

void Graphics::recreateWindow(SIrrlichtCreationParameters param)
	{
		device = createDeviceEx(param);

		smgr = device->getSceneManager();
		driver = device->getVideoDriver();
		gi = device->getGUIEnvironment();
	};

A simple function to recreate. When I'm debugging on line 2 of this code I put in a breakpoint which tells me param contains:
WindowSize {Width=1280 Height = 1024}
Bits = 32 ' '
ZBufferBits = 16 ''
Etc. Etc.
All correct values. When I press F5, VS appears to freeze, as the window in the foreground takes control and you cant access VS. Right clicking the program of my creation and clicking "Close" via windows then allows me back to VS and shows me:
Unhandled Exception 0x00480c85 in Win32Learn.exe: 0xC0000005: Access violation reading location 0x00000000.
It also shows me in the background that param now equals:
DriverType = 2147328000
And other seemlingly trash values.
I am unsure how, between line 2 and 3 of my code these could change and cause a crash. Of course, I have researched this topic and other have had problems with releasing of resources aka, not unloading textures before restart so I will post my shutting down function to.

Code: Select all

void Graphics::endDevice()
{
		gi->clear();
		smgr->clear();

		driver->removeAllHardwareBuffers();
		driver->removeAllTextures();

		device->closeDevice();
		device->run();
		device->drop();
};

Any help would be appreciated. Thanks.
But the cage only had "Warning: Vicious Lions" on it! Im a programmer! I only listen to errors!
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

i dont think you should try run something thats closed/ended.

device->closeDevice();
device->run();

That makes little sense to me, and seems like it will cause access violations
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, that's ok and should be done to cope with close events sent by the OS.
Are you sure that the debugger is still on line 3? I'd guess that it has made its way to the main app and your fault is somewhere there. The param values are completely wrong then, because they are only temporary values, being overwritten later on by something completely different.
LordNyson
Posts: 31
Joined: Tue Nov 11, 2008 12:02 pm
Location: Perth, Australia

Post by LordNyson »

Yeah, its possible that its somewhere else, but I can't tell because you can't see VS because the program freezes. I'll link some more code.

Code: Select all

int main()
{
	GraphicsWindow graphicsWindow;
	Graphics graphicsDriver;
	GraphicsDoc graphicsDocument;

	SIrrlichtCreationParameters param;
	graphics graphicsVariables;
	GUI graphicsGUI;

	graphicsDocument.read(&graphicsVariables,&param);
	graphicsDriver.beginEngine(&param);

	MyEventReceiver ev;

	ev.setGraphicsActive(true);

 while(ev.getGraphicsActive() == true)
 {
	graphicsWindow.draw(&graphicsGUI);
	ev.setGraphicsActive(true);

	int p = 0;

	device->setEventReceiver(&ev);

	while (device->run() && ev.getGraphicsActive() == true)
	{
		driver->beginScene(true, true, video::SColor(255,113,113,133));
		smgr->drawAll();
		gi->drawAll();
	
		driver->endScene();

		if(ev.getGUIid() == 259)
			graphicsWindow.update(&graphicsGUI);
	}
	
	if(ev.getGraphicsActive() == false)
	{
		graphicsDocument.read(&graphicsVariables,&param);
		graphicsDriver.endDevice();
		graphicsDriver.recreateWindow(param);
		ev.setGraphicsActive(true);
	};
 };
	device->closeDevice();
	device->drop();

	return 0;
};

But the cage only had "Warning: Vicious Lions" on it! Im a programmer! I only listen to errors!
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Simply step through your code in the debugger. After each call you will get back to the debugger, no freeze until you find the correct place. Moreover, try to enable the DX Debug settings to avoid problems with unsupported parameters.
LordNyson
Posts: 31
Joined: Tue Nov 11, 2008 12:02 pm
Location: Perth, Australia

Post by LordNyson »

Mmk so your saying step into the CreateDeviceEx Function? Also, how would I enable the DX Debug?
But the cage only had "Warning: Vicious Lions" on it! Im a programmer! I only listen to errors!
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, you need to single step until the error happens, or you jump across the function calls and need to single step only in the one that hangs in the first approach.
The DX Debug mode is set via the DX Control Panel from DX SDK.
LordNyson
Posts: 31
Joined: Tue Nov 11, 2008 12:02 pm
Location: Perth, Australia

Post by LordNyson »

Ok so, I worked out some of my error. Before loading a new screen it reads from a .dat file. It reads values from this .dat file, such as rez. The .dat file was set to 1920x1200 where my rez is 1920x1080, it also was set to fullscreen, which appears to have difficulty loading anything that is above 800x600. Apon deletion of the .dat file, it creates a new one. As such I deleted it, and can now change some options without it stopping on that line of code. If however, I put it into FS it will always give me an access violation.

Basically, I have also tried to a do a more thoughrough debug, but unfortunately, it will not allow me to step into that line of code. I press F11 and it gives me the access violation without opening up any irrlicht code, I also reset device to NULL, but that didn't help. I am currently downloading the DX SDK, so once that has finished I will update this post whether with a solution or just more specifics on the problem, based on the DX Debug.

Thanks for all your help so far.

I have found the cause. Basically I was using a bunch of resolutions that were given to me by friends. Wrong move. I took proper rezes, and sorted them in my application based on Aspect Ratio, then made a revert function that reverts the graphical changes should an access violation occur. So basically, if you choose a rez that is incompatible with your screen it will revert to your previous options. Simple, once you find the error eh? *Rolls eyes*.

Anyway thanks very much for all your input.
But the cage only had "Warning: Vicious Lions" on it! Im a programmer! I only listen to errors!
Post Reply