Skip to content

Commit

Permalink
Fix actual source of the crash
Browse files Browse the repository at this point in the history
Co-authored-by: ferociousdork <[email protected]>
  • Loading branch information
dseguin committed Oct 3, 2021
1 parent 416e385 commit d710af6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/npctrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const skill_id skill_speech( "speech" );
static const flag_id json_flag_NO_UNWIELD( "NO_UNWIELD" );

std::list<item> npc_trading::transfer_items( std::vector<item_pricing> &stuff, Character &giver,
Character &receiver, std::list<item_location> &from_map, bool npc_gives )
Character &receiver, std::list<item_location *> &from_map, bool npc_gives )
{
// escrow is used only when the npc is the destination. Item transfer to the npc is deferred.
const bool use_escrow = !npc_gives;
Expand Down Expand Up @@ -83,7 +83,7 @@ std::list<item> npc_trading::transfer_items( std::vector<item_pricing> &stuff, C
}
sorted_stuff.insert( sorted_stuff.begin(), unsorted_stuff.begin(), unsorted_stuff.end() );

for( item_pricing ip : sorted_stuff ) {
for( item_pricing &ip : sorted_stuff ) {

if( ip.loc.get_item() == nullptr ) {
DebugLog( D_ERROR, D_NPC ) << "Null item being traded in npc_trading::transfer_items";
Expand Down Expand Up @@ -137,7 +137,7 @@ std::list<item> npc_trading::transfer_items( std::vector<item_pricing> &stuff, C
} else {
ip.loc.get_item()->set_var( "trade_amount", 1 );
}
from_map.emplace_back( ip.loc );
from_map.push_back( &ip.loc );
}
}
return escrow;
Expand Down Expand Up @@ -809,7 +809,7 @@ bool npc_trading::trade( npc &np, int cost, const std::string &deal )
if( traded ) {
int practice = 0;

std::list<item_location> from_map;
std::list<item_location *> from_map;

std::list<item> escrow;
avatar &player_character = get_avatar();
Expand All @@ -821,23 +821,23 @@ bool npc_trading::trade( npc &np, int cost, const std::string &deal )
np.i_add( i, true, nullptr, nullptr, true, false );
}

for( item_location &loc_ptr : from_map ) {
for( item_location *loc_ptr : from_map ) {
if( !loc_ptr ) {
continue;
}
item *it = loc_ptr.get_item();
item *it = loc_ptr->get_item();
if( !it ) {
continue;
}
if( it->has_var( "trade_charges" ) && it->count_by_charges() ) {
it->charges -= static_cast<int>( it->get_var( "trade_charges", 0 ) );
if( it->charges <= 0 ) {
loc_ptr.remove_item();
loc_ptr->remove_item();
} else {
it->erase_var( "trade_charges" );
}
} else if( it->has_var( "trade_amount" ) ) {
loc_ptr.remove_item();
loc_ptr->remove_item();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/npctrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int cash_to_favor( const npc &, int cash );

std::list<item> transfer_items( std::vector<item_pricing> &stuff, Character &giver,
Character &receiver,
std::list<item_location> &from_map, bool npc_gives );
std::list<item_location *> &from_map, bool npc_gives );
double net_price_adjustment( const Character &buyer, const Character &seller );
bool trade( npc &p, int cost, const std::string &deal );
std::vector<item_pricing> init_selling( npc &p );
Expand Down

0 comments on commit d710af6

Please sign in to comment.