Skip to content

Commit

Permalink
set target in Bat.updatePosition if unset (#363)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmitshur authored Jul 5, 2021
1 parent be4ef39 commit df95f15
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -3513,4 +3516,4 @@ struct Winston : Enemy {
}
};

#endif
#endif

0 comments on commit df95f15

Please sign in to comment.