Make clearBuffs memory-safe

improperly erasing during iteration oops
This commit is contained in:
gsemaj 2023-08-13 18:26:30 -07:00
parent 478ae3d996
commit da33c5c30f
No known key found for this signature in database
GPG Key ID: 24B96BAA40497929

View File

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