Skip to content

Commit 726816a

Browse files
authored
Merge pull request CleverRaven#83385 from inogenous/prevent-segfault-when-cancelling-completed-butchery
Prevent segfault when cancelling butchery
1 parent 51324ee commit 726816a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/activity_actor.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9139,14 +9139,11 @@ void butchery_activity_actor::do_turn( player_activity &act, Character &you )
91399139
}
91409140

91419141
if( this_bd->progress >= this_bd->time_to_butcher ) {
9142+
const butchery_data bd_copy = *this_bd;
9143+
bd.pop_back();
91429144
// this corpse is done
9143-
destroy_the_carcass( *this_bd, you );
9144-
if( bd.empty() ) {
9145-
act.moves_left = 0;
9146-
return;
9147-
} else {
9148-
bd.pop_back();
9149-
}
9145+
destroy_the_carcass( bd_copy, you );
9146+
// WARNING: destroy_the_carcass might spill acid, which gives the player the option to cancel this activity. If so, then `this` might be invalidated, along with all `butchery_data` elements. So here we need to be sure to not use either of those after this call.
91509147
} else {
91519148
this_bd->progress += 1_seconds;
91529149
// Uses max(1, ..) to prevent it going all the way to zero, which would stop the activity by the general `activity_actor` handling.

src/butchery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ void destroy_the_carcass( const butchery_data &bd, Character &you )
11751175
you.recoil = MAX_RECOIL;
11761176

11771177
get_event_bus().send<event_type::character_butchered_corpse>( you.getID(),
1178-
corpse_item.get_mtype()->id, "ACT_" + io::enum_to_string<butcher_type>( bd.b_type ) );
1178+
corpse->id, "ACT_" + io::enum_to_string<butcher_type>( action ) );
11791179

11801180
}
11811181

0 commit comments

Comments
 (0)