Fix a rare crash in flyer.c with self->enemy being NULL

This crash was found by DanielGibson, he even guessed the right fix
without having a usable coredump. ;) In boss1.bsp Macron is waiting for
the player, despawning as soon as the player moves to him. After that
the player needs to press 2 buttons, each button triggers 3 flyers. If
the player is fast enough, the first bunch of flyers may spawn before
macron is despawned. Now there's a small chance that a flyer decides to
attack macron... If Macron despwans at the the next frame, self->enemy
is set to NULL (Macron is gone) but nevertheless flyer_fire() is called.

The correct fix would be to call flyer_fire() before Macron despawns,
but that's hard to impossible. So take the easy route and check if
self->enemy is not NULL.
This commit is contained in:
Yamagi Burmeister 2016-11-04 19:22:33 +01:00
parent 548c217da8
commit 5e5217e549

View file

@ -496,7 +496,7 @@ flyer_fire(edict_t *self, int flash_number)
vec3_t dir;
int effect;
if (!self)
if (!self || !self->enemy)
{
return;
}