[fixed]Bug in looped animation

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

[fixed]Bug in looped animation

Post by B@z »

hi
i found an interesting glitch in irrlicht 1.6

i place an animated, looped character somewhere, it works cool.
but then if i pause the render (debugging, or just use the pause button), the frame glitches.
it jumps over the EndFrame, and start playing the animation reversed until it reaches the EndFrame.
the problem is that it does the same thing when loading (so there is a pause)
in my game, i load things, then show up my model. but because the loading pause, the frame glitch appears, and my character is moving wierd xD

after looking into irrlicht code, what changed i found this:

Code: Select all

void CAnimatedMeshSceneNode::buildFrameNr(u32 timeMs)
// ....
	else if (Looping)
	{
		// play animation looped
		CurrentFrameNr += timeMs * FramesPerSecond;
		if (FramesPerSecond > 0.f) //forwards...
		{
			if (CurrentFrameNr > EndFrame)
				CurrentFrameNr -= (EndFrame-StartFrame);
		}
		else //backwards...
		{
			if (CurrentFrameNr < StartFrame)
				CurrentFrameNr += (EndFrame-StartFrame);
		}
	}
it looks good at first sight, but just think about it.

StartFrame = 5
EndFrame = 10
FramesPerSecond = 0.025
CurrentFrameNr = 7
i had a big pause, so the timeMs is 4200 (just for testing)

CurrentFrameNr += 4200 * 0.025; (112)
CurrentFrameNr -= (10-5); (107)

and next run
timeMs = 1
CurrentFrameNr(107) += 1*0.025; (107.025)
CurrentFrameNr -= (10-5); (102.025);

etc. so it goes back to EndFrame, then because the CurrentFrameNr -= (EndFrame-StartFrame);, it returns to StartFrame, and everything going well from now.

in irrlicht 1.5 it was good (the code was different), but this one really looks ugly (i wonder why nobody posted about it in forums)

and the solution (at last worked for me, i dunno if its fast enough, or have some problem)

Code: Select all

	else if (Looping)
	{
		// play animation looped
		CurrentFrameNr += timeMs * FramesPerSecond;
		if (FramesPerSecond > 0.f) //forwards...
		{
			if (CurrentFrameNr > EndFrame)
				CurrentFrameNr = StartFrame + fmod(CurrentFrameNr - EndFrame, (f32)(EndFrame-StartFrame));
		}
		else //backwards...
		{
			if (CurrentFrameNr < StartFrame)
				CurrentFrameNr = EndFrame - fmod(StartFrame - CurrentFrameNr, (f32)(EndFrame-StartFrame));
		}
	}
EDIT: oops, seems like % works only with int. changed to fmod
Image
Image
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Hm, I've seen this change already and also wondered about it. But probably there was some reason....

Can you please put an entry for that on the bugtracker?
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
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

yeah, tried to replace it with the older code, but it didnt work.. maybe something changed with the variables.
anyway, sent ticket
Image
Image
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ok, thanks.
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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, the fix sounds reasonable. I guess we should put this into 1.6 branch in order to get this corrected as early as possible.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

okay, downloaded 1.7.1 aaaaaand the bug still exists xD
i mean u forgot to change the code

and i dont wanna open a new topic for that, but i would be happy if the getJointNode wouldn't give error if couldnt find specific bone.
i mean im checking if the returned value is null, then why does it gives a warning message?
yea we can turn off warning messages, but i want to see the other warnings, just dont want it to spam my console (coz im trying to get bones in every frame)
its not a big problem, but i have to rebuild the engine every time a new comes out >.>
Image
Image
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

We did not forget it and it is still on the bugtracker. The problem is that it is the way it is now because that fixed another bug (see http://sourceforge.net/tracker/?func=de ... tid=540678). Just returning to the old bug isn't really a solution. So we first have to write some tests for all the different situations which can happen so we don't mess it up again. I also wish we would have found time to fix the animations bugs before 1.7 releases, but it just didn't work out. If I ever manage to get a full day for Irrlicht again the animation troubles will be my first priority. But maybe someone else is interested enough to write a bunch of good tests for that for us - actually fixing it is then probably rather easy.

The getJointForNode warnings might have been worth an own topic. Because I think we should have another logging-level for that - ELL_WARNING is imho way to high here and I wouldn't even like to use ELL_INFORMATION. Most logging libraries have some DEBUG level for such stuff, so what I would like to do is to introduce ELL_DEBUG. But I will talk with the team about that first.
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
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

well i dont think thats a good idea leaving the bugged version..
i dont know whats the problem with the old one(i mean my fix), but works better than the current version. its pretty ugly

but ok, i thought u forgot it, and wanted to remind
Image
Image
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

B@z wrote:well i dont think thats a good idea leaving the bugged version..
No, certainly not. I really hope one of us finds time soon for that bug. The problem is not that there is something wrong with your fix, but that we don't know if there is something wrong with it or not before someone writes some tests. It's not the fixing that is blocking this - it is figuring out if the fix this time will solve the troubles. You get a lot more careful when you find out that the reason it's broken is that someone tried to fix another bug. Also it's probably a good idea to care about the other animation problem at the same time, the thing that setAnimationSpeed shouldn't change the current frame.
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
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

oh now i understand what u meant.
i hope someone will work on that too
Image
Image
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I fixed it now in the 1.7 svn branch. Did it a little bit different than you, but should work.

There's still another problem which I found when fixing this one. It seems right now we don't interpolate between the last and the first frame. So the only way animations work correct is when the first and last frame are identical. I suppose this isn't like it should be, but changing this is more tricky (I suppose we would have to run CurrentFrameNr to EndFrame+1 and then catch this situation in the place where we do the real interpolation). So something for another day.

For easier testing the meshviewer example shows frames now.

Sorry for taking that long to fix this bug.
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
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

thanks for fixing~

well what you said.. i never saw any 3d software or engine what interpolated between the first and the end frame. i think, that doesnt annoy anyone XD
Image
Image
Post Reply