Make clearBuffs memory-safe

improperly erasing during iteration oops
This commit is contained in:
gsemaj 2023-08-13 18:26:30 -07:00 committed by gsemaj
parent b04c292272
commit e64bcf91a5

View File

@ -61,14 +61,13 @@ void Player::removeBuff(int buffId, BuffClass buffClass) {
} }
void Player::clearBuffs(bool force) { void Player::clearBuffs(bool force) {
for(auto buff : buffs) { auto it = buffs.begin();
if(!force) { while(it != buffs.end()) {
removeBuff(buff.first); Buff* buff = (*it).second;
} else { if(!force) buff->clear();
delete buff.second; delete buff;
} it = buffs.erase(it);
} }
buffs.clear();
} }
bool Player::hasBuff(int buffId) { bool Player::hasBuff(int buffId) {
@ -217,14 +216,13 @@ void CombatNPC::removeBuff(int buffId, BuffClass buffClass) {
} }
void CombatNPC::clearBuffs(bool force) { void CombatNPC::clearBuffs(bool force) {
for(auto buff : buffs) { auto it = buffs.begin();
if(!force) { while(it != buffs.end()) {
removeBuff(buff.first); Buff* buff = (*it).second;
} else { if(!force) buff->clear();
delete buff.second; delete buff;
} it = buffs.erase(it);
} }
buffs.clear();
} }
bool CombatNPC::hasBuff(int buffId) { bool CombatNPC::hasBuff(int buffId) {