Cleanup AudioEngine resource after exiting NewAudioEngineTest. (#17675)

* Unschedules update in AudioEngine implementation while AudioEngine::end is called.

* Cleanup AudioEngine resource after exiting NewAudioEngineTest.
This commit is contained in:
James Chen 2017-04-13 17:58:49 +08:00 committed by minggo
parent 75d0ebfefc
commit 3c1e36c2c3
5 changed files with 23 additions and 0 deletions

View File

@ -192,12 +192,18 @@ static id s_AudioEngineSessionHandler = nullptr;
AudioEngineImpl::AudioEngineImpl()
: _lazyInitLoop(true)
, _currentAudioID(0)
, _scheduler(nullptr)
{
}
AudioEngineImpl::~AudioEngineImpl()
{
if (_scheduler != nullptr)
{
_scheduler->unschedule(CC_SCHEDULE_SELECTOR(AudioEngineImpl::update), this);
}
if (s_ALContext) {
alDeleteSources(MAX_AUDIOINSTANCES, _alSources);

View File

@ -112,12 +112,18 @@ static ALCcontext *s_ALContext = nullptr;
AudioEngineImpl::AudioEngineImpl()
: _lazyInitLoop(true)
, _currentAudioID(0)
, _scheduler(nullptr)
{
}
AudioEngineImpl::~AudioEngineImpl()
{
if (_scheduler != nullptr)
{
_scheduler->unschedule(CC_SCHEDULE_SELECTOR(AudioEngineImpl::update), this);
}
if (s_ALContext) {
alDeleteSources(MAX_AUDIOINSTANCES, _alSources);

View File

@ -38,6 +38,8 @@ AudioEngineImpl::AudioEngineImpl()
AudioEngineImpl::~AudioEngineImpl()
{
auto scheduler = cocos2d::Director::getInstance()->getScheduler();
scheduler->unschedule(schedule_selector(AudioEngineImpl::update), this);
_audioCaches.clear();
}

View File

@ -207,6 +207,12 @@ std::string AudioEngineTestDemo::title() const
return "New Audio Engine Test";
}
void AudioEngineTestDemo::onBackCallback(cocos2d::Ref* sender)
{
AudioEngine::end();
TestCase::onBackCallback(sender);
}
// AudioControlTest
bool AudioControlTest::init()
{

View File

@ -41,6 +41,9 @@ public:
virtual std::string title() const override;
virtual void onExit() override;
virtual void onBackCallback(cocos2d::Ref* sender) override;
protected:
std::shared_ptr<bool> _isDestroyed;
};