summaryrefslogtreecommitdiff
path: root/src/particle
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-23 02:14:30 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-23 02:14:30 +0300
commit6a65a4cf5b6b10839254c0c5846ec2dbfea882f8 (patch)
treecdf1dcc071ab18575defff569d33f3cbc8be0348 /src/particle
parent1a5f8957c707625efbcf36722b057d5eda5a21bb (diff)
downloadmanaverse-6a65a4cf5b6b10839254c0c5846ec2dbfea882f8.tar.gz
manaverse-6a65a4cf5b6b10839254c0c5846ec2dbfea882f8.tar.bz2
manaverse-6a65a4cf5b6b10839254c0c5846ec2dbfea882f8.tar.xz
manaverse-6a65a4cf5b6b10839254c0c5846ec2dbfea882f8.zip
Allow delete untracker being particle effects.
This fix some possible memory leaks.
Diffstat (limited to 'src/particle')
-rw-r--r--src/particle/particle.cpp11
-rw-r--r--src/particle/particle.h7
-rw-r--r--src/particle/particlelist.cpp5
3 files changed, 21 insertions, 2 deletions
diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp
index 4e7b154c0..a04cee6f3 100644
--- a/src/particle/particle.cpp
+++ b/src/particle/particle.cpp
@@ -22,8 +22,11 @@
#include "particle/particle.h"
+#include "actormanager.h"
#include "logger.h"
+#include "being/actorsprite.h"
+
#include "particle/animationparticle.h"
#include "particle/particleemitter.h"
#include "particle/rotationalparticle.h"
@@ -61,6 +64,7 @@ Particle::Particle() :
mType(ParticleType::Normal),
mAnimation(nullptr),
mImage(nullptr),
+ mActor(BeingId_zero),
mChildEmitters(),
mChildParticles(),
mChildMoveParticles(),
@@ -82,6 +86,13 @@ Particle::Particle() :
Particle::~Particle()
{
+ if (mActor != BeingId_zero &&
+ actorManager)
+ {
+ ActorSprite *const actor = actorManager->findActor(mActor);
+ if (actor)
+ actor->controlParticleDeleted(this);
+ }
// Delete child emitters and child particles
clear();
delete2(mAnimation);
diff --git a/src/particle/particle.h b/src/particle/particle.h
index f1a8154b6..859a61505 100644
--- a/src/particle/particle.h
+++ b/src/particle/particle.h
@@ -28,6 +28,8 @@
#include "enums/particle/alivestatus.h"
#include "enums/particle/particletype.h"
+#include "enums/simpletypes/beingid.h"
+
#include "particle/particleengine.h"
#include "localconsts.h"
@@ -238,6 +240,9 @@ class Particle notfinal : public Actor
const signed char conditions) restrict2
{ mDeathEffect = effectFile; mDeathEffectConditions = conditions; }
+ void setActor(const BeingId actor)
+ { mActor = actor; }
+
protected:
void updateSelf() restrict2;
@@ -270,6 +275,8 @@ class Particle notfinal : public Actor
/**< The image used for this particle. */
Image *restrict mImage;
+ BeingId mActor;
+
private:
// List of child emitters.
Emitters mChildEmitters;
diff --git a/src/particle/particlelist.cpp b/src/particle/particlelist.cpp
index 0d2a2f195..209ecfd32 100644
--- a/src/particle/particlelist.cpp
+++ b/src/particle/particlelist.cpp
@@ -44,8 +44,6 @@ void ParticleList::addLocally(Particle *const particle)
{
if (particle)
{
- // The effect may not die without the beings permission or we segfault
- particle->disableAutoDelete();
mElements.push_back(particle);
mSize ++;
}
@@ -74,7 +72,10 @@ void ParticleList::removeLocally(const Particle *const particle)
void ParticleList::clearLocally()
{
FOR_EACH (ParticleListCIter, it, mElements)
+ {
(*it)->kill();
+ (*it)->prepareToDie();
+ }
mElements.clear();
mSize = 0U;