mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-16 19:20:05 +00:00
Make clearBuffs
memory-safe
improperly erasing during iteration oops
This commit is contained in:
parent
b04c292272
commit
e64bcf91a5
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user