Skip to content

Commit

Permalink
Fix a crash in the playanim script command
Browse files Browse the repository at this point in the history
The code that scheduled the animation completion script callback did
not handle cases where setting the animation failed/was skipped.
For example, this could happen with dead NPCs.

Fixes: crash report #383
  • Loading branch information
dscharrer committed Dec 6, 2012
1 parent 9fe682b commit 1989703
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/script/ScriptedAnimation.cpp
Expand Up @@ -233,9 +233,11 @@ class PlayAnimCommand : public Command {
return Failed;
}

ANIM_USE & layer = iot->animlayer[nu];

if(anim == "none") {
iot->animlayer[nu].cur_anim = NULL;
iot->animlayer[nu].next_anim = NULL;
layer.cur_anim = NULL;
layer.next_anim = NULL;
return Success;
}

Expand All @@ -258,7 +260,7 @@ class PlayAnimCommand : public Command {
}

if(iot == entities.player()) {
iot->animlayer[nu].flags &= ~EA_STATICANIM;
layer.flags &= ~EA_STATICANIM;
}

if(execute) {
Expand All @@ -277,7 +279,14 @@ class PlayAnimCommand : public Command {
scr_timer[num2].es = context.getScript();
scr_timer[num2].exist = 1;
scr_timer[num2].io = context.getIO();
scr_timer[num2].msecs = max(iot->anims[num]->anims[iot->animlayer[nu].altidx_cur]->anim_time, 1000.f);
scr_timer[num2].msecs = 1000.f;
// Don't assume that we successfully set the animation - use the current animation
if(layer.cur_anim) {
arx_assert(layer.altidx_cur >= 0 && layer.altidx_cur < layer.cur_anim->alt_nb);
if(layer.cur_anim->anims[layer.altidx_cur]->anim_time > scr_timer[num2].msecs) {
scr_timer[num2].msecs = layer.cur_anim->anims[layer.altidx_cur]->anim_time;
}
}
scr_timer[num2].name = timername;
scr_timer[num2].pos = pos;
scr_timer[num2].tim = (unsigned long)(arxtime);
Expand Down

0 comments on commit 1989703

Please sign in to comment.