Hi, I’m using custom eventlistener Director::EVENT_RESET to do some clean up, and I noticed that Director is holding on to the scenes in _scenesStack. This causes the running scene to not be cleared until the next line.
So I modified to move the clearing other held stack before the event listener is fired. Is that a safe modification? I don’t quite understand what the notificationNode is used for.
void Director::reset()
{
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
if (_runningScene)
{
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
if (sEngine)
{
sEngine->releaseScriptObject(this, _runningScene);
}
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
_runningScene->onExit();
_runningScene->cleanup();
_runningScene->release();
}
_runningScene = nullptr;
_nextScene = nullptr;
//MODIFIED I move this here, is it safe?
// This releases the scene when EVENT_RESET is fired
while (!_scenesStack.empty())
_scenesStack.popBack();
if (_eventDispatcher)
_eventDispatcher->dispatchEvent(_eventResetDirector);
// cleanup scheduler
getScheduler()->unscheduleAll();
// Remove all events
if (_eventDispatcher)
_eventDispatcher->removeAllEventListeners();
if(_notificationNode)
{
_notificationNode->onExit();
_notificationNode->cleanup();
_notificationNode->release();
}
_notificationNode = nullptr;
// remove all objects, but don't release it.
// runWithScene might be executed after 'end'.
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
if (sEngine)
{
for (const auto &scene : _scenesStack)
{
if (scene)
sEngine->releaseScriptObject(this, scene);
}
}
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
// Director still holds the current running scene here
//while (!_scenesStack.empty())
// _scenesStack.popBack();