1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +00:00

fix some rare crashes with dangling pointers

- Always handle entity death ie. do pointer cleanup
- Call Lua entityDied() only when EV_ENTITYDIED is set
- EV_ENTITYDIED is now meaningless for non-scripted entities
This commit is contained in:
fgenesis 2023-09-13 23:56:11 +02:00
parent c1084a022d
commit bf58fe91c6
6 changed files with 18 additions and 35 deletions

View file

@ -3063,11 +3063,6 @@ void Avatar::setBlockSinging(bool v)
}
}
bool Avatar::canSetBoneLock()
{
return true;
}
void Avatar::onSetBoneLock()
{
Entity::onSetBoneLock();

View file

@ -300,8 +300,6 @@ public:
Web *web;
float rollDelay;
bool canSetBoneLock() OVERRIDE;
void revert();
void doBindSong();
void doShieldSong();

View file

@ -61,17 +61,18 @@ void Entity::setIngredientData(const std::string &name)
void Entity::entityDied(Entity *e)
{
for (size_t i = 0; i < targets.size(); i++)
if(targets[i] == e)
targets[i] = NULL;
if (boneLock.on && boneLock.entity == e)
{
targets[i] = 0;
setBoneLock(BoneLock(), true);
}
if (boneLock.on)
{
if (boneLock.entity == e)
{
setBoneLock(BoneLock());
}
}
if(riding == e)
riding = NULL;
if(ridingOnEntity == e)
ridingOnEntity = NULL;
}
void Entity::setBounceType(BounceType bt)
@ -98,14 +99,13 @@ void Entity::generateCollisionMask(int ovrCollideRadius)
}
}
bool Entity::setBoneLock(const BoneLock &bl)
bool Entity::setBoneLock(const BoneLock &bl, bool force)
{
if (!canSetBoneLock()) return false;
if (bl.on && boneLockDelay > 0) return false;
if (boneLock.on && bl.on) return false;
if(!force)
{
if (bl.on && boneLockDelay > 0) return false;
if (boneLock.on && bl.on) return false;
}
if (boneLock.on && !bl.on)
{
@ -138,11 +138,6 @@ bool Entity::setBoneLock(const BoneLock &bl)
return true;
}
bool Entity::canSetBoneLock()
{
return true;
}
Entity::Entity()
{
addType(SCO_ENTITY);

View file

@ -91,7 +91,7 @@ public:
float health;
float maxHealth;
bool setBoneLock(const BoneLock &boneLock);
bool setBoneLock(const BoneLock &boneLock, bool force = false);
void heal(float a, int type=0);
@ -330,8 +330,6 @@ public:
void setPoison(float m, float t);
inline float getPoison() const { return poison; }
virtual bool canSetBoneLock();
void initHair(int numSegments, float segmentLength, float width, const std::string &tex);
void updateHair(float dt);
void setHairHeadPosition(const Vector &pos);

View file

@ -2333,10 +2333,7 @@ void Game::entityDied(Entity *eDead)
FOR_ENTITIES(i)
{
e = *i;
if (e != eDead && e->isv(EV_ENTITYDIED,1))
{
e->entityDied(eDead);
}
e->entityDied(eDead);
}
dsq->continuity.entityDied(eDead);

View file

@ -688,7 +688,7 @@ void ScriptedEntity::entityDied(Entity *e)
{
CollideEntity::entityDied(e);
if (script)
if (script && e != this && e->isv(EV_ENTITYDIED,1))
{
script->call("entityDied", this, e);
}