From 5c182c7fd795e9f525dbdf8409b1cc87bbf38f93 Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Fri, 8 Jul 2016 11:55:04 +0200 Subject: [PATCH] Fixed a crash with heretic's ChickenPlayer class --- src/d_player.h | 5 ++++- src/g_heretic/a_chicken.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 48649de7ad..e932223aaa 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -532,7 +532,10 @@ public: void TickPSprites(); void DestroyPSprites(); DPSprite *FindPSprite(int layer); - DPSprite *GetPSprite(PSPLayers layer); // Used ONLY for compatibility with the old hardcoded layers. + // Used ONLY for compatibility with the old hardcoded layers. + // Make sure that a state is properly set after calling this unless + // you are 100% sure the context already implies the layer exists. + DPSprite *GetPSprite(PSPLayers layer); }; // Bookkeeping on players - state. diff --git a/src/g_heretic/a_chicken.cpp b/src/g_heretic/a_chicken.cpp index b70e4ff080..7f62d5f0e1 100644 --- a/src/g_heretic/a_chicken.cpp +++ b/src/g_heretic/a_chicken.cpp @@ -123,9 +123,10 @@ DEFINE_ACTION_FUNCTION(AActor, A_Feathers) void P_UpdateBeak (AActor *self) { - if (self->player != nullptr) + DPSprite *pspr; + if (self->player != nullptr && (pspr = self->player->FindPSprite(PSP_WEAPON)) != nullptr) { - self->player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP + self->player->chickenPeck / 2; + pspr->y = WEAPONTOP + self->player->chickenPeck / 2; } }