From b6416309c175a584d67d4dac97a59b36af35ebbe Mon Sep 17 00:00:00 2001 From: David Seguin Date: Thu, 18 Aug 2022 03:13:59 -0400 Subject: [PATCH] fix: prevent use of non valid creature pointer --- src/effect_on_condition.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/effect_on_condition.cpp b/src/effect_on_condition.cpp index 12c7ff794d7a8..a56d1cb2b2b97 100644 --- a/src/effect_on_condition.cpp +++ b/src/effect_on_condition.cpp @@ -387,9 +387,12 @@ void effect_on_conditions::write_global_eocs_to_file( ) void effect_on_conditions::avatar_death() { avatar &player_character = get_avatar(); - dialogue d( get_talker_for( get_avatar() ), - player_character.get_killer() == nullptr ? nullptr : get_talker_for( - player_character.get_killer() ) ); + Creature *klr = player_character.get_killer(); + // Make sure the creature still exists in game + klr = !klr ? klr : g->get_creature_if( [klr]( const Creature & c ) { + return klr == &c; + } ); + dialogue d( get_talker_for( get_avatar() ), klr == nullptr ? nullptr : get_talker_for( klr ) ); for( const effect_on_condition &eoc : effect_on_conditions::get_all() ) { if( eoc.type == eoc_type::AVATAR_DEATH ) { eoc.activate( d );