From f6bdbfe53568dd49b6227ecea3bd3cce051ef9ac Mon Sep 17 00:00:00 2001 From: Zandrewnum Date: Tue, 9 Mar 2021 11:47:05 -0700 Subject: [PATCH] APROP_SoundClass inits a default value and checks for null pointers - Gave default init value to SoundClass as "Player" - Changed SoundClass detection to use the if/else structure - Checked for null pointer in S_FindSkinnedSound when reading the player's sound class --- src/playsim/d_player.h | 2 +- src/sound/s_advsound.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/playsim/d_player.h b/src/playsim/d_player.h index 3dc3acc16..97460b427 100644 --- a/src/playsim/d_player.h +++ b/src/playsim/d_player.h @@ -391,7 +391,7 @@ public: float BlendB = 0; float BlendA = 0; - FString SoundClass; + FString SoundClass = "Player"; FString LogText; // [RH] Log for Strife FString SubtitleText; int SubtitleCounter; diff --git a/src/sound/s_advsound.cpp b/src/sound/s_advsound.cpp index 49660e9c2..80a3973da 100644 --- a/src/sound/s_advsound.cpp +++ b/src/sound/s_advsound.cpp @@ -1620,7 +1620,11 @@ static const char *GetSoundClass(AActor *pp) } auto sclass = player? pp->NameVar(NAME_SoundClass) : NAME_None; - sclass != NAME_None ? pp->player->SoundClass = sclass.GetChars() : (FString)"player"; + if (sclass != NAME_None) + pp->player->SoundClass = sclass.GetChars(); + else + pp->player->SoundClass = "Player"; + return sclass != NAME_None ? sclass.GetChars() : "player"; } @@ -1638,7 +1642,7 @@ int S_FindSkinnedSound (AActor *actor, FSoundID refid) if (actor != nullptr) { - pclass = actor->player->SoundClass; + if (actor->player != nullptr) pclass = actor->player->SoundClass; if (actor->player != nullptr) gender = actor->player->userinfo.GetGender(); } else