getTime problems

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
Sigutis
Posts: 10
Joined: Thu May 01, 2008 8:51 am
Location: Lithuania

getTime problems

Post by Sigutis »

I have a problem with time function in my event receiver;

here's a fragment
u32 time1 global

Code: Select all

		if(event.EventType == EET_MOUSE_INPUT_EVENT &&
			event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP){
			time1=device->getTimer()->getTime();

		}
It compiles fine, but when I actually press the mouse button it crashes
CuteAlien
Admin
Posts: 10021
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: getTime problems

Post by CuteAlien »

device could be an invalid pointer and it could be a problem outside the code you posted.
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
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Most likely, the 'device' inside your event receiver isn't set, e.g. you've declared a global 'device' and then a local one inside your main.

There, I've now taken longer to type this than it would take you to find out using your debugger.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Sigutis
Posts: 10
Joined: Thu May 01, 2008 8:51 am
Location: Lithuania

fa

Post by Sigutis »

Rogerboards guess was correct. But solution to this problem leads to another bug.

thanks
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I'm sorry, I don't know how to solve your new bug. :P
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Sigutis
Posts: 10
Joined: Thu May 01, 2008 8:51 am
Location: Lithuania

sdf

Post by Sigutis »

Its ok I forgive you :D
This one shall be a challenge for me
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Hang on, Vitek will be along in a moment. He'll figure it out. ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Sigutis
Posts: 10
Joined: Thu May 01, 2008 8:51 am
Location: Lithuania

sads

Post by Sigutis »

Whel my code is quite messy and all but I'll try to explain.
This is supposed to be an RPG game.
I made a global device and few variables

Code: Select all

IrrlichtDevice* device = 0;
int atstumas;
u32 timetorun,time1;
Then goes my event receiver class.
A mouse method from it:

Code: Select all

vector3df coords;  //storage for the player coordinates (node)
		if(event.EventType == EET_MOUSE_INPUT_EVENT &&
			event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP){
			coord=node->getPosition();   atstumas=sqrt((coord.X-intersection.X)*(coord.X-intersection.X)+(coord.Y-intersection.Y)*(coord.Y-intersection.Y));
//atstumas calculates the way between node and his target
		timetorun=atstumas*5;
			node->setFrameLoop(1, 2500); //set node to run
			node->setRotation(faceTarget(intersection,coord));
//rotate node to target			anim=smgr->createFlyStraightAnimator(coord,intersection,u32)timetorun,false);
		    node->addAnimator(anim);
			anim->drop();
//animator to walk to the target
			time1=device->getTimer()->getTime();
//I use time1 to know when the animation should stop
		}
in main I actually create the device

Code: Select all

	device =
		createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(640, 480), 16,
			false, false, false, &receiver);
And the main loop

Code: Select all

		if (time1-device->getTimer()->getTime()+timetorun<0)
			node->setFrameLoop(1,1);
//after after timetorun we turn the object to standing frame again
Player animation stopped just fine before I changed

IrrlichtDevice* device =
createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(640, 480), 16,
false, false, false, &receiver);

to

device =
createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(640, 480), 16,
false, false, false, &receiver);

Now it just continues to run even when the character is already at the target.

After some test I believe function device->getTimer()->getTime() returns negative value :o
Post Reply