diff --git a/src/lightmap.cpp b/src/lightmap.cpp index 2feb464bfe6af..4bf3ea4e2210c 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -63,7 +63,7 @@ std::string four_quadrants::to_string() const } void map::add_light_from_items( const tripoint &p, item_stack::iterator begin, - map_stack::iterator end ) + item_stack::iterator end ) { for( auto itm_it = begin; itm_it != end; ++itm_it ) { float ilum = 0.0; // brightness diff --git a/src/map.cpp b/src/map.cpp index d7a4cf4d862a7..9295f665a686f 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -4132,7 +4132,10 @@ map_stack::iterator map::i_rem( const tripoint &p, map_stack::const_iterator it void map::i_rem( const tripoint &p, item *it ) { map_stack map_items = i_at( p ); - map_items.erase( map_items.get_iterator_from_pointer( it ) ); + map_stack::const_iterator iter = map_items.get_iterator_from_pointer( it ); + if( iter != map_items.end() ) { + i_rem( p, iter ); + } } void map::i_clear( const tripoint &p ) diff --git a/src/map.h b/src/map.h index 30f48a721007d..19bd4bdf6a136 100644 --- a/src/map.h +++ b/src/map.h @@ -1567,7 +1567,7 @@ class map void apply_light_arc( const tripoint &p, int angle, float luminance, int wideangle = 30 ); void apply_light_ray( bool lit[MAPSIZE_X][MAPSIZE_Y], const tripoint &s, const tripoint &e, float luminance ); - void add_light_from_items( const tripoint &p, item_stack::iterator begin, map_stack::iterator end ); + void add_light_from_items( const tripoint &p, item_stack::iterator begin, item_stack::iterator end ); std::unique_ptr add_vehicle_to_map( std::unique_ptr veh, bool merge_wrecks ); // Internal methods used to bash just the selected features diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index fa66b3bfeb81f..a939c124508f9 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -3484,7 +3484,7 @@ void submap::load( JsonIn &jsin, const std::string &member_name, bool rubpow_upd return VisitResponse::NEXT; } ); - colony::iterator it = itm[p.x][p.y].insert( tmp ); + const colony::iterator it = itm[p.x][p.y].insert( tmp ); if( tmp.needs_processing() ) { active_items.add( it, p ); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2800ae4722593..c70816f490861 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -4443,20 +4443,15 @@ cata::optional vehicle::add_item( int part, const item return cata::optional( new_pos ); } -bool vehicle::remove_item( int part, const item *it ) +bool vehicle::remove_item( int part, item *it ) { - bool rc = false; - colony &veh_items = parts[part].items; - - for( auto iter = veh_items.begin(); iter != veh_items.end(); ++iter ) { - //delete the item if the pointer memory addresses are the same - if( it == &*iter ) { - remove_item( part, iter ); - rc = true; - break; - } + const colony &veh_items = parts[part].items; + const colony::const_iterator iter = veh_items.get_iterator_from_pointer( it ); + if( iter == veh_items.end() ) { + return false } - return rc; + remove_item( part, iter ); + return true; } vehicle_stack::iterator vehicle::remove_item( int part, vehicle_stack::const_iterator it )