I just updated a project to cocos2d-x 3.15, and noticed that AppDelegate.cpp now has the following code:
AppDelegate::~AppDelegate()
{
#if USE_AUDIO_ENGINE
AudioEngine::end();
#elif USE_SIMPLE_AUDIO_ENGINE
SimpleAudioEngine::end();
#endif
}
USE_AUDIO_ENGINE is defined, so it’s calling “AudioEngine::end();” in the AppDelegate destructor, but when it does so, it crashes.
AudioEngine::end() does this “delete _audioEngineImpl;”, then in “AudioEngineImpl::~AudioEngineImpl”, it does the following:
if (_scheduler != nullptr)
{
_scheduler->unschedule(CC_SCHEDULE_SELECTOR(AudioEngineImpl::update), this);
}
....
This is where the crash happens, in CCScheduler.cpp, function Scheduler::unschedule:
void Scheduler::unschedule(SEL_SCHEDULE selector, Ref *target)
{
// explicit handle nil arguments when removing an object
if (target == nullptr || selector == nullptr)
{
return;
}
tHashTimerEntry *element = nullptr;
HASH_FIND_PTR(_hashForTimers, &target, element); <= crashes right here, with "_hashForTimers" having an invalid value (such as 0xDDDDDDDD).
I have absolutely no idea why this is happening, and will look into it further, but just on a quick glance I don’t actually know what this section of code does, nor why _hashForTimers would contain an invalid value.
Before I log this in as an issue, has anyone else experienced this crash, or have an idea why it may be happening?
It is reproducible, and happens any time I close the game application.