setLoopMode() crashes my app

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!
Post Reply
binford
Posts: 28
Joined: Tue Nov 14, 2006 10:32 am
Location: Munich

setLoopMode() crashes my app

Post by binford »

Hi there,

I use static meshes and animate them with flyStraightAnimators. I'd like to create a new animator whenever the last animation is finished. I thought the OnAnimationEnd callback would be a good solution for that. The callback stuff seems to work but as soon as I call setLoopMode( false ), the app crashes.

Code: Select all

 
// do the animation
mp_unitNode->setLoopMode( false );

ISceneNodeAnimator* anim = mp_sm->createFlyStraightAnimator( mp_unitNode->getPosition(), firstField->getCenterPosition(), 1000, false );
mp_unitNode->addAnimator( anim );

mp_unitNode->setAnimationEndCallback( this );
anim->drop();
This code even crashs when I do not set the callback.

Any ideas?

[EDIT: I just commented out everything in the function except setLoopMode(), it still crashs. The pointer is a valid one! ]
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Are you absolutely sure that you have a valid scene node pointer. Just because it is not pointing to NULL does not mean that it is a valid pointer. You might try changeing mp_unitNode->setLoopMode( false ) to mp_unitNode->getAbsoluteTransformation() to see if it still crashes.

Travis
binford
Posts: 28
Joined: Tue Nov 14, 2006 10:32 am
Location: Munich

Post by binford »

No the pointer is valid. I tried what you told me. It's in fact not the setLoopMode() method where the app crashs, but the next CAnimatedMeshSceneNode->render() call in the next render loop. If I omit setLoopMode() the app doesent crash at that point.

I would step through the irrlicht code but gdb doesent let me step into sceneManager->drawAll() but tells me about a segfault.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Try making your own delta-timed fly striaght animator. Its not very hard and you can implement your own setLoopMode function. Irrlicht's fly straight animators while handy at times can be very stuffy, (for instance it refused to set one after the draw loop, and therefore cannot be called from inside anotehr animator.) I recommend a custom scene node animator for this job. Although getting the delta timing 100% can be pretty damn confusing...

Heres a small example:

Code: Select all

(make a "float currenttime;" and initiate it to 0 somewhere in the constructor)
if(currenttime != 0){node->setPosition((f32)velocity * (f32)(timeMs - currenttime));}
currenttime = timeMs;
 
I wrote that quickly by hand so theres bound to be something i forgot lol...hope it helps though!

OH woops. I just realised this has NOTHING to do with setLoopMode...
Ummm nevermind then!

PS: But how can static meshes have animation!? Also what format is your model?
binford
Posts: 28
Joined: Tue Nov 14, 2006 10:32 am
Location: Munich

Post by binford »

My meshes are OBJ files. I experimented a lot with diferent formats and obj was pretty much the only one that worked. I only animate them within irrlicht (e.g. move the whole object form one point to another.

I already thought about coding my own animator but I always try to make as much use of Irrlicht features as possible.

The Task (just to let you know):
Im coding an RTS game and the units should follow some waypoints they store internally. With the flyStraightAnimator, I would have added an animator whenever the last animator is fisnished. But if I have to code my own animator, I guess my animator will take care of the whole path at once.

thanks for your help.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Isnt setLoopMode for actual animated meshes?! As in X or B3D or MD2, with vertex or bone animations. Not SceneNodeAnimators lol...obj files I dont think have any sort of animation atleast in Irrlicht eh. So setLoopMode will not have any effect even if it did work, because what it does is repeat the animation once the animation frames have finished (Actual mesh animation not SceneNodeAnimators).

Here is a description of setLoopMode:

Code: Select all

		//! Sets looping mode which is on by default. If set to false,
		//! animations will not be played looped.
Note ANIMATIONS not ANIMATORS...
binford
Posts: 28
Joined: Tue Nov 14, 2006 10:32 am
Location: Munich

Post by binford »

Isnt setLoopMode for actual animated meshes?!
I think you are right, but it doesent really matter in my case. I only call setLoopMode( false ) because if I would'nt, the OnAnimationEnd() callback won't be triggered. And the OnAnimationEnd() callback does work, it gets called after my animator is done.

IMHO setLoopMode should not crash just because my meshes dont have animations. btw the app doesent crash if I call setLoopMode( true ).

I think its a bug, but this might be overhastly.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

In my game projects that use fly straight animators I just make a new one every frame and that works fine...I don't think it is as resource consuming as you may think, give it a try.

PS: I am confused you say the callback only works when the loop mode is set to false but so far it only crashes when you set it to false?
binford
Posts: 28
Joined: Tue Nov 14, 2006 10:32 am
Location: Munich

Post by binford »

PS: I am confused you say the callback only works when the loop mode is set to false but so far it only crashes when you set it to false?
Yep thats right. The callback works, but in the next render loop somwhere in CAnimatedMeshSeceneNode->render() the app crashs if setLoopMode is set to false.

I'll code my own animator which takes care of all those waypoints at once. Seems to me to be more efficient than creating a new animator every frame.
Post Reply