Skip to content

Commit

Permalink
Update monster deaths to return nullptr (#54632)
Browse files Browse the repository at this point in the history
Fixes an issue when a corpse can't be created, which should return a
nullptr, not a null item.

fixes #53785, fixes #54603

Co-authored-by: Binrui Dong <brett.browning.dong@gmail.com>
  • Loading branch information
gruebite and BrettDong committed Jan 21, 2022
1 parent d0deb00 commit 5ac1a12
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/mondeath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ item *mdeath::normal( monster &z )
if( pulverized ) {
return splatter( z );
} else {
return make_mon_corpse( z, static_cast<int>( std::floor( corpse_damage * itype::damage_scale ) ) );
const float damage = std::floor( corpse_damage * itype::damage_scale );
item *corpse = make_mon_corpse( z, static_cast<int>( damage ) );
if( corpse->is_null() ) {
return nullptr;
}
return corpse;
}
}
return nullptr;
Expand Down Expand Up @@ -187,6 +192,9 @@ item *mdeath::splatter( monster &z )
}
// add corpse with gib flag
item corpse = item::make_corpse( z.type->id, calendar::turn, z.unique_name, z.get_upgrade_time() );
if( corpse.is_null() ) {
return nullptr;
}
// Set corpse to damage that aligns with being pulped
corpse.set_damage( 4000 );
corpse.set_flag( STATIC( flag_id( "GIBBED" ) ) );
Expand Down

0 comments on commit 5ac1a12

Please sign in to comment.