From 1ed056beaa89b3b5bf8476f01fff424e3869da9e Mon Sep 17 00:00:00 2001 From: BevapDin Date: Sun, 3 May 2020 10:20:47 +0200 Subject: [PATCH] Prevent attempt to removing an item from itself. The code calls `visitable::visit_items` and adds all items to be removed as reported by the lambda to the vector and later calls `visitable::remove_item` for all those listed items. But `visit_items` will visit `this` as well. So the vector ends up containing `this`, which is subsequently given to `remove_item`, which complains (correctly) that `this` is not contains in `this`. --- src/item.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 4c6805886f40e..7d961f874fb25 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -9488,9 +9488,13 @@ bool item::process( player *carrier, const tripoint &pos, bool activate, float i return VisitResponse::NEXT; } ); for( item *it : removed_items ) { - remove_item( *it ); + // remove_item can not remove `this` itself, so don't even try. + if( it != this ) { + remove_item( *it ); + } } - return !removed_items.empty(); + // Inform the caller that they need to remove `this`. + return std::find( removed_items.begin(), removed_items.end(), this ) != removed_items.end(); } bool item::process_internal( player *carrier, const tripoint &pos, bool activate,