Pawn.cpp: fixed effect iterator BAD_ACCESS
Erasure was occurring before the iterator increased, causing a bad access. Solved by storing map pairs in variables and manually updating iterator before erasure. Fixed mix-up in function arguments on food poisoning
This commit is contained in:
parent
e98ffccd80
commit
615152eb8c
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height)
|
cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height)
|
||||||
: cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height)
|
: cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height)
|
||||||
, m_EntityEffects(std::map<cEntityEffect::eType, cEntityEffect>())
|
, m_EntityEffects(tEffectMap())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,20 +21,25 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height)
|
|||||||
void cPawn::Tick(float a_Dt, cChunk & a_Chunk)
|
void cPawn::Tick(float a_Dt, cChunk & a_Chunk)
|
||||||
{
|
{
|
||||||
// Iterate through this entity's applied effects
|
// Iterate through this entity's applied effects
|
||||||
for (tEffectMap::iterator iter = m_EntityEffects.begin();
|
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
|
||||||
iter != m_EntityEffects.end();
|
|
||||||
++iter)
|
|
||||||
{
|
{
|
||||||
|
// Copies values to prevent pesky wrong accesses and erasures
|
||||||
|
cEntityEffect::eType effect_type = iter->first;
|
||||||
|
cEntityEffect &effect_values = iter->second;
|
||||||
|
|
||||||
// Apply entity effect
|
// Apply entity effect
|
||||||
HandleEntityEffects(iter->first, iter->second);
|
HandleEntityEffects(effect_type, effect_values);
|
||||||
|
|
||||||
// Reduce the effect's duration
|
// Reduce the effect's duration
|
||||||
iter->second.m_Ticks--;
|
effect_values.m_Ticks--;
|
||||||
|
|
||||||
|
// Iterates (must be called before any possible erasure)
|
||||||
|
++iter;
|
||||||
|
|
||||||
// Remove effect if duration has elapsed
|
// Remove effect if duration has elapsed
|
||||||
if (iter->second.m_Ticks <= 0)
|
if (effect_values.m_Ticks <= 0)
|
||||||
{
|
{
|
||||||
RemoveEntityEffect(iter->first);
|
RemoveEntityEffect(effect_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check for discrepancies between client and server effect values
|
// TODO: Check for discrepancies between client and server effect values
|
||||||
|
@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation)
|
|||||||
|
|
||||||
void cPlayer::FoodPoison(int a_NumTicks)
|
void cPlayer::FoodPoison(int a_NumTicks)
|
||||||
{
|
{
|
||||||
AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(0, a_NumTicks, NULL));
|
AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(a_NumTicks, 0, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user