Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash for malformed mining activity. #46020

Merged
merged 1 commit into from
Dec 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,6 @@ void activity_handlers::pickaxe_finish( player_activity *act, player *p )
{
map &here = get_map();
const tripoint pos( here.getlocal( act->placement ) );
item &it = *act->targets.front();
// Invalidate the activity early to prevent a query from mod_pain()
act->set_to_null();
if( p->is_avatar() ) {
Expand Down Expand Up @@ -1817,9 +1816,11 @@ void activity_handlers::pickaxe_finish( player_activity *act, player *p )
_( "You finish digging." ),
_( "<npcname> finishes digging." ) );
here.destroy( pos, true );
it.charges = std::max( 0, it.charges - it.type->charges_to_use() );
if( it.charges == 0 && it.destroyed_at_zero_charges() ) {
p->i_rem( &it );
if( !act->targets.empty() ) {
item &it = *act->targets.front();
p->consume_charges( it, it.ammo_required() );
} else {
debugmsg( "pickaxe activity targets empty" );
}
if( resume_for_multi_activities( *p ) ) {
for( item &elem : here.i_at( pos ) ) {
Expand Down Expand Up @@ -3839,6 +3840,12 @@ void activity_handlers::jackhammer_finish( player_activity *act, player *p )
_( "You finish drilling." ),
_( "<npcname> finishes drilling." ) );
act->set_to_null();
if( !act->targets.empty() ) {
item &it = *act->targets.front();
p->consume_charges( it, it.ammo_required() );
} else {
debugmsg( "jackhammer activity targets empty" );
}
if( resume_for_multi_activities( *p ) ) {
for( item &elem : here.i_at( pos ) ) {
elem.set_var( "activity_var", p->name );
Expand Down