Skip to content

Commit

Permalink
Merge pull request #39566 from Qrox/fix-use-amount-crash
Browse files Browse the repository at this point in the history
Fix a crash in item::use_amount
  • Loading branch information
ZhilkinSerg authored Apr 14, 2020
2 parents bd43707 + e471d95 commit 66dad5a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8002,6 +8002,7 @@ bool item::use_amount( const itype_id &it, int &quantity, std::list<item> &used,
{
// Remember quantity so that we can unseal self
int old_quantity = quantity;
std::vector<item *> removed_items;
// First, check contents
visit_items(
[&]( item * a ) {
Expand All @@ -8010,12 +8011,16 @@ bool item::use_amount( const itype_id &it, int &quantity, std::list<item> &used,
return VisitResponse::NEXT;
}
if( a->use_amount_internal( it, quantity, used, filter ) ) {
this->remove_item( *a );
removed_items.emplace_back( a );
return VisitResponse::SKIP;
}
return VisitResponse::NEXT;
} );

for( item *remove : removed_items ) {
remove_item( *remove );
}

if( quantity != old_quantity ) {
on_contents_changed();
}
Expand Down

0 comments on commit 66dad5a

Please sign in to comment.