Memory optimization by making m_refundableItems a std::set<uint64>. Also fix a crash caused by invalid iterator in Player::_SaveInventory(). This should fix the last of the item save related crashes.
--HG-- branch : trunk
This commit is contained in:
+1
-1
@@ -1084,7 +1084,7 @@ void Item::SetNotRefundable(Player *owner, bool changestate)
|
||||
SetPaidExtendedCost(0);
|
||||
DeleteRefundDataFromDB();
|
||||
|
||||
owner->DeleteRefundReference(this);
|
||||
owner->DeleteRefundReference(GetGUID());
|
||||
}
|
||||
|
||||
void Item::UpdatePlayedTime(Player *owner)
|
||||
|
||||
+12
-7
@@ -16412,7 +16412,7 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
|
||||
item->SetRefundRecipient(fields[0].GetUInt32());
|
||||
item->SetPaidMoney(fields[1].GetUInt32());
|
||||
item->SetPaidExtendedCost(fields[2].GetUInt32());
|
||||
AddRefundReference(item);
|
||||
AddRefundReference(item->GetGUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17499,9 +17499,14 @@ void Player::_SaveInventory()
|
||||
// the client auto counts down in real time after having received the initial played time on the first
|
||||
// SMSG_ITEM_REFUND_INFO_RESPONSE packet.
|
||||
// Item::UpdatePlayedTime is only called when needed, which is in DB saves, and item refund info requests.
|
||||
for (std::set<Item*>::iterator itr = m_refundableItems.begin(); itr!= m_refundableItems.end(); ++itr)
|
||||
std::set<uint64>::iterator i_next;
|
||||
for (std::set<uint64>::iterator itr = m_refundableItems.begin(); itr!= m_refundableItems.end(); itr = i_next)
|
||||
{
|
||||
Item* iPtr = *itr;
|
||||
// use copy iterator because UpdatePlayedTime may invalidate itr
|
||||
i_next = itr;
|
||||
++i_next;
|
||||
|
||||
Item* iPtr = GetItemByGuid(*itr);
|
||||
ASSERT(iPtr); // Sanity check, if this assertion is hit then the item wasn't removed from the set correctly./
|
||||
iPtr->UpdatePlayedTime(this);
|
||||
}
|
||||
@@ -19362,7 +19367,7 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
|
||||
it->SetPaidMoney(price);
|
||||
it->SetPaidExtendedCost(crItem->ExtendedCost);
|
||||
it->SaveRefundDataToDB();
|
||||
AddRefundReference(it);
|
||||
AddRefundReference(it->GetGUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19420,7 +19425,7 @@ bool Player::BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint
|
||||
it->SetPaidMoney(price);
|
||||
it->SetPaidExtendedCost(crItem->ExtendedCost);
|
||||
it->SaveRefundDataToDB();
|
||||
AddRefundReference(it);
|
||||
AddRefundReference(it->GetGUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23347,12 +23352,12 @@ void Player::SendDuelCountdown(uint32 counter)
|
||||
GetSession()->SendPacket(&data);
|
||||
}
|
||||
|
||||
void Player::AddRefundReference(Item* it)
|
||||
void Player::AddRefundReference(uint64 it)
|
||||
{
|
||||
m_refundableItems.insert(it);
|
||||
}
|
||||
|
||||
void Player::DeleteRefundReference(Item* it)
|
||||
void Player::DeleteRefundReference(uint64 it)
|
||||
{
|
||||
m_refundableItems.erase(it);
|
||||
}
|
||||
+3
-3
@@ -1190,8 +1190,8 @@ class Player : public Unit, public GridObject<Player>
|
||||
uint8 _CanTakeMoreSimilarItems(uint32 entry, uint32 count, Item* pItem, uint32* no_space_count = NULL) const;
|
||||
uint8 _CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 entry, uint32 count, Item *pItem = NULL, bool swap = false, uint32* no_space_count = NULL ) const;
|
||||
|
||||
void AddRefundReference(Item* it);
|
||||
void DeleteRefundReference(Item* it);
|
||||
void AddRefundReference(uint64 it);
|
||||
void DeleteRefundReference(uint64 it);
|
||||
|
||||
void ApplyEquipCooldown( Item * pItem );
|
||||
void SetAmmo( uint32 item );
|
||||
@@ -2558,7 +2558,7 @@ class Player : public Unit, public GridObject<Player>
|
||||
uint8 _CanStoreItem_InInventorySlots( uint8 slot_begin, uint8 slot_end, ItemPosCountVec& dest, ItemPrototype const *pProto, uint32& count, bool merge, Item *pSrcItem, uint8 skip_bag, uint8 skip_slot ) const;
|
||||
Item* _StoreItem( uint16 pos, Item *pItem, uint32 count, bool clone, bool update );
|
||||
|
||||
std::set<Item*> m_refundableItems;
|
||||
std::set<uint64> m_refundableItems;
|
||||
|
||||
void UpdateKnownCurrencies(uint32 itemId, bool apply);
|
||||
int32 CalculateReputationGain(uint32 creatureOrQuestLevel, int32 rep, int32 faction, bool for_quest);
|
||||
|
||||
Reference in New Issue
Block a user