Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions core/base/Director.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,41 +1165,42 @@ void Director::setNextScene()
{
_eventDispatcher->dispatchEvent(_beforeSetNextScene);

bool runningIsTransition = dynamic_cast<TransitionScene*>(_runningScene) != nullptr;
bool newIsTransition = dynamic_cast<TransitionScene*>(_nextScene) != nullptr;
auto outgoingScene = _runningScene;
_runningScene = _nextScene;
_nextScene = nullptr;

// If it is not a transition, call onExit/cleanup
if (!newIsTransition)
bool outgoingSceneIsTransition = dynamic_cast<TransitionScene*>(outgoingScene) != nullptr;

if (outgoingScene)
{
if (_runningScene)
{
_runningScene->onExitTransitionDidStart();
_runningScene->onExit();
}
bool incomingSceneIsTransition = dynamic_cast<TransitionScene*>(_runningScene) != nullptr;

// issue #709. the root node (scene) should receive the cleanup message too
// otherwise it might be leaked.
if (_sendCleanupToScene && _runningScene)
// If it is not a transition, call onExit/cleanup
if (!incomingSceneIsTransition)
{
_runningScene->cleanup();
outgoingScene->onExitTransitionDidStart();
outgoingScene->onExit();

// issue #709. the root node (scene) should receive the cleanup message too
// otherwise it might be leaked.
if (_sendCleanupToScene)
{
outgoingScene->cleanup();
}
}

outgoingScene->release();
}

if (_runningScene)
{
_runningScene->release();
}
_runningScene = _nextScene;
if (_nextScene)
{
_nextScene->retain();
}
_nextScene = nullptr;
_runningScene->retain();

if ((!runningIsTransition) && _runningScene)
{
_runningScene->onEnter();
_runningScene->onEnterTransitionDidFinish();
if (!outgoingSceneIsTransition)
{
_runningScene->onEnter();
_runningScene->onEnterTransitionDidFinish();
}
}

_eventDispatcher->dispatchEvent(_afterSetNextScene);
Expand Down