Merge pull request #6040 from dumganhar/develop

Two fixes: 1) ParticleSystem should also override onExit to unschedule update since in onEnter, it will be scheduled again. Otherwise, it'll trigger an assert.
2) User object has to be released before others, since userObject may have a weak reference of this node. It may invoke node->stopAllAction(); while _actionManager is null if the next line is after CC_SAFE_RELEASE_NULL(_actionManager).
This commit is contained in:
James Chen 2014-03-28 14:13:02 +08:00
commit 9090e2015c
3 changed files with 12 additions and 2 deletions

View File

@ -154,6 +154,10 @@ Node::~Node()
}
#endif
// User object has to be released before others, since userObject may have a weak reference of this node
// It may invoke `node->stopAllAction();` while `_actionManager` is null if the next line is after `CC_SAFE_RELEASE_NULL(_actionManager)`.
CC_SAFE_RELEASE_NULL(_userObject);
CC_SAFE_RELEASE_NULL(_actionManager);
CC_SAFE_RELEASE_NULL(_scheduler);
@ -162,7 +166,6 @@ Node::~Node()
// attributes
CC_SAFE_RELEASE_NULL(_shaderProgram);
CC_SAFE_RELEASE_NULL(_userObject);
for (auto& child : _children)
{

View File

@ -624,6 +624,12 @@ void ParticleSystem::onEnter()
this->scheduleUpdateWithPriority(1);
}
void ParticleSystem::onExit()
{
this->unscheduleUpdate();
Node::onExit();
}
void ParticleSystem::stopSystem()
{
_isActive = false;

View File

@ -191,7 +191,6 @@ public:
//! whether or not the system is full
bool isFull();
virtual void onEnter();
//! should be overridden by subclasses
virtual void updateQuadWithParticle(tParticle* particle, const Point& newPosition);
//! should be overridden by subclasses
@ -355,6 +354,8 @@ public:
inline void setPositionType(PositionType type) { _positionType = type; };
// Overrides
virtual void onEnter() override;
virtual void onExit() override;
virtual void update(float dt) override;
virtual Texture2D* getTexture() const override;
virtual void setTexture(Texture2D *texture) override;