From df95f15adf9fd4ae71a092a251694f682c47d7a5 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sun, 4 Jul 2021 21:13:17 -0400 Subject: [PATCH] set target in Bat.updatePosition if unset (#363) Prevent a null pointer dereference if updatePosition is called before the enemy gets a chance to think, such as when loading a game involving a flying bat with unlucky timing. Fixes #362. --- src/enemy.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/enemy.h b/src/enemy.h index 32b756b5..d83afe67 100644 --- a/src/enemy.h +++ b/src/enemy.h @@ -1611,6 +1611,9 @@ struct Bat : Enemy { virtual void updatePosition() { turn(state == STATE_FLY || state == STATE_ATTACK, BAT_TURN_SPEED); + if (!target) + target = (Character*)game->getLara(pos); + if (flying) { float wy = waypoint.y - (target->stand != STAND_ONWATER ? 765.0f : 64.0f); lift(wy - pos.y, BAT_LIFT_SPEED); @@ -3513,4 +3516,4 @@ struct Winston : Enemy { } }; -#endif \ No newline at end of file +#endif