Merge pull request #6032 from boyu0/4573_Particle_setVisible_crash

closed #4573: Set particle visible to false then set to true cause crashes.
This commit is contained in:
minggo 2014-03-28 10:08:39 +08:00
commit de9c5b34c1
4 changed files with 46 additions and 4 deletions

View File

@ -685,7 +685,6 @@ void ParticleSystem::update(float dt)
currentPosition = _position;
}
if (_visible)
{
while (_particleIdx < _particleCount)
{
@ -826,7 +825,9 @@ void ParticleSystem::update(float dt)
} //while
_transformSystemDirty = false;
}
if (! _batchNode)
// only update gl buffer when visible
if (_visible && ! _batchNode)
{
postStep();
}

View File

@ -360,7 +360,7 @@ void ParticleSystemQuad::postStep()
// overriding draw method
void ParticleSystemQuad::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad");
CCASSERT( _particleIdx == 0 || _particleIdx == _particleCount, "Abnormal error in particle quad");
//quad command
if(_particleIdx > 0)
{

View File

@ -1009,13 +1009,14 @@ Layer* createParticleLayer(int nIndex)
case 43: return new PremultipliedAlphaTest2();
case 44: return new Issue3990();
case 45: return new ParticleAutoBatching();
case 46: return new ParticleVisibleTest();
default:
break;
}
return NULL;
}
#define MAX_LAYER 46
#define MAX_LAYER 47
Layer* nextParticleAction()
@ -1939,6 +1940,37 @@ std::string Issue3990::subtitle() const
}
// ParticleVisibleTest
void ParticleVisibleTest::onEnter()
{
ParticleDemo::onEnter();
_emitter = ParticleFireworks::create();
_emitter->retain();
_background->addChild(_emitter, 10);
_emitter->setTexture( Director::getInstance()->getTextureCache()->addImage(s_stars1) );
schedule(schedule_selector(ParticleVisibleTest::callback), 1);
setEmitterPosition();
}
std::string ParticleVisibleTest::title() const
{
return "Issue4573";
}
std::string ParticleVisibleTest::subtitle() const
{
return "Visible enable/disable";
}
void ParticleVisibleTest::callback(float delta)
{
_emitter->setVisible(!_emitter->isVisible());
}
//
// ParticleAutoBatching
//

View File

@ -310,6 +310,15 @@ public:
virtual std::string subtitle() const override;
};
class ParticleVisibleTest : public ParticleDemo
{
public:
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void callback(float delta);
};
class ParticleAutoBatching : public ParticleDemo
{
public: