Device in fullscreen 16:9

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

This should not happen.
Can you show us some code that produces this error?
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Gendo Ikari
Posts: 19
Joined: Mon Apr 13, 2009 5:42 pm

Post by Gendo Ikari »

In main.h

Code: Select all

IrrlichtDevice *device;
IrrlichtDevice	*devNull;
IVideoModeList *vidlist;
IVideoDriver *driver;
ISceneManager *smgr;
Events events;
ICameraSceneNode *camera;
in main.cpp

Code: Select all

//when form is create
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{

	devNull = createDevice(EDT_NULL);
	vidlist = devNull->getVideoModeList();
	for (int i = 0; i < vidlist->getVideoModeCount(); i++) {
		this->cbbRes->Items->Add(
			IntToStr((vidlist->getVideoModeResolution(i)).Width) + "x" +
			IntToStr((vidlist->getVideoModeResolution(i)).Height) +  "x" +
			IntToStr(vidlist->getVideoModeDepth(i))
			);
	}
	this->cbbRes->ItemIndex=0;
	this->cbbDriver->ItemIndex=0;
}
//-------------------------------------------------------------------
//when i click start button after chose resolution
void __fastcall TfrmMain::btnStartClick(TObject *Sender)
{
	E_DRIVER_TYPE tmpDriver;
	dimension2d<s32> tmpRes;
	u32 tmpBits;
	switch (this->cbbDriver->ItemIndex) {
		case 0:
			tmpDriver = EDT_DIRECT3D9;
			break;
		case 1:
			tmpDriver = EDT_OPENGL;
			break;
		case 2:
			tmpDriver = EDT_SOFTWARE;
			break;
	}
	tmpRes = vidlist->getVideoModeResolution(this->cbbRes->ItemIndex);
	tmpBits = vidlist->getVideoModeDepth(this->cbbRes->ItemIndex);
	devNull->drop();
	device = createDevice(tmpDriver,tmpRes,tmpBits,this->lstOptions->Checked[0],
		this->lstOptions->Checked[1],this->lstOptions->Checked[2],&events);
	if (!device) {
		this->Close();
	}
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	device->setWindowCaption(L"The Master Thief");
	//preparazione della scena
	camera = smgr->addCameraSceneNode(0,vector3df(0,40,-100),vector3df(0,10,0));
	IAnimatedMesh *mesh = smgr->getMesh("sydney.md2");
	ILightSceneNode *light = smgr->addLightSceneNode(0,vector3df(0,10,10),
		SColor(255,255,128,128),150.0f);
	if (!mesh) {
		this->Close();
	}
	IAnimatedMeshSceneNode *node =smgr->addAnimatedMeshSceneNode(mesh);
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, true);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	}
	this->Hide();
	this->IrrLoop();
}
//-------------------------------------------------------------------
//the irrlicht loop
void __fastcall TfrmMain::IrrLoop()
{
	u32 shot_old = device->getTimer()->getTime();
	while (device->run())
	{
		const u32 shot_now = device->getTimer()->getTime();
		const f32 shot_delta = (f32) (shot_now-shot_old);
		shot_old = shot_now;

		driver->beginScene(true,true,SColor(255,255,255,255));


		if (events.IsKeyDown(KEY_ESCAPE)) {
			device->closeDevice();
		}
		if (events.IsKeyDown(KEY_KEY_A)) {
			vector3df camPos = camera->getPosition();
			vector3df camTPos = camera->getTarget();
			camPos.X -= 0.1f*shot_delta;
			camTPos.X -= 0.1f*shot_delta;
			camera->setPosition(camPos);
			camera->setTarget(camTPos);
		}
		if (events.IsKeyDown(KEY_KEY_D)) {
			vector3df camPos = camera->getPosition();
			vector3df camTPos = camera->getTarget();
			camPos.X += 0.1f*shot_delta;
			camTPos.X += 0.1f*shot_delta;
			camera->setPosition(camPos);
			camera->setTarget(camTPos);
		}
		if (events.IsKeyDown(KEY_KEY_W)) {
			vector3df camPos = camera->getPosition();
			vector3df camTPos = camera->getTarget();
			camPos.Z += 0.1f*shot_delta;
			camTPos.Z += 0.1f*shot_delta;
			camera->setPosition(camPos);
			camera->setTarget(camTPos);
		}
		if (events.IsKeyDown(KEY_KEY_S)) {
			vector3df camPos = camera->getPosition();
			vector3df camTPos = camera->getTarget();
			camPos.Z -= 0.1f*shot_delta;
			camTPos.Z -= 0.1f*shot_delta;
			camera->setPosition(camPos);
			camera->setTarget(camTPos);
		}

		smgr->drawAll();
		driver->endScene();
	}
	device->drop();
	this->Close();

}
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

try calling closeDevice() before drop()
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Gendo Ikari
Posts: 19
Joined: Mon Apr 13, 2009 5:42 pm

Post by Gendo Ikari »

I've done yet. Same problem. The error happen when i close programm, so its something about cleaning resources by irrlicht imho.
Gendo Ikari
Posts: 19
Joined: Mon Apr 13, 2009 5:42 pm

Post by Gendo Ikari »

Maybe irrlicht does something strange when a device get dropped. If a implement a check like this:

Code: Select all

	if (device) {
		device->drop();
	}
	if (devNull) {
		devNull->drop();
	}
all goes well on the surface.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You should drop devNull immediately when you have the information which you needed. Right now if btnStartClick is called more than once then devNull will be dropped several times.

It is easier to find such bugs (and good style) when you set variables always to 0 after you dropped them.

(also that was the first time I've ever seen someone using __fastcall)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Gendo Ikari
Posts: 19
Joined: Mon Apr 13, 2009 5:42 pm

Post by Gendo Ikari »

1) Start button cannot be called more than once, because the frmMain disappear when device start.
2) If I drop devNull immediately after using it the program crash at end, in the same way. The error happen not in my code, but in irrlicht code.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Well then take your debugger and look where exactly it crashes.
I never had any problems droping any device.

Maybe this is a problem with borland (you are using borland, aren't you?)
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Gendo Ikari wrote:Maybe irrlicht does something strange when a device get dropped. If a implement a check like this:

Code: Select all

	if (device) {
		device->drop();
	}
	if (devNull) {
		devNull->drop();
	}
all goes well on the surface.
That would not prevent dropping a device several times. You have to reset a variable if you want check it:

Code: Select all

	if (device) {
		device->drop();
		device = 0;
	}
	if (devNull) {
		devNull->drop();
		devNull = 0;
	}
Otherwise no idea, I guess many people (including myself) do use some null device and drop it additional to the other device. So I wouldn't really expect this to be a problem in Irrlicht code. Just try doing a small example where you do nothing at all besides the create, drop, create, drop of those 2 devices. Does it still crash?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Gendo Ikari
Posts: 19
Joined: Mon Apr 13, 2009 5:42 pm

Post by Gendo Ikari »

Good advice, thank you all :D
Borland doenst exist anymore ç_ç now is Embarcadero CodeGear RadStudio. Once upon a time there was an ide called Borland C++ Builder ç_ç
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

So the same thing with a different name?
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Gendo Ikari
Posts: 19
Joined: Mon Apr 13, 2009 5:42 pm

Post by Gendo Ikari »

Its not only the name. Its the quality.
Post Reply