Adds `Renderer::clean`, and fixes crash in `PerformanceTest/Node

children Test`.
This commit is contained in:
James Chen 2014-04-04 12:48:16 +08:00
parent fe036c3870
commit 7b4a1308ea
3 changed files with 22 additions and 3 deletions

View File

@ -359,6 +359,12 @@ void Renderer::render()
} }
} }
clean();
}
void Renderer::clean()
{
// Clear render group
for (size_t j = 0 ; j < _renderGroups.size(); j++) for (size_t j = 0 ; j < _renderGroups.size(); j++)
{ {
//commands are owned by nodes //commands are owned by nodes
@ -368,12 +374,18 @@ void Renderer::render()
// } // }
_renderGroups[j].clear(); _renderGroups[j].clear();
} }
//Clear the stack incase gl view hasn't been initialized yet // Clear batch quad commands
_batchedQuadCommands.clear();
_numQuads = 0;
// Clear the stack incase gl view hasn't been initialized yet
while(!_renderStack.empty()) while(!_renderStack.empty())
{ {
_renderStack.pop(); _renderStack.pop();
} }
// Reset render stack
RenderStackElement element = {DEFAULT_RENDER_QUEUE, 0}; RenderStackElement element = {DEFAULT_RENDER_QUEUE, 0};
_renderStack.push(element); _renderStack.push(element);
_lastMaterialID = 0; _lastMaterialID = 0;

View File

@ -79,7 +79,7 @@ public:
//TODO manage GLView inside Render itself //TODO manage GLView inside Render itself
void initGLView(); void initGLView();
/** Adds a `RenderComamnd` into the renderer */ /** Adds a `RenderComamnd` into the renderer */
void addCommand(RenderCommand* command); void addCommand(RenderCommand* command);
@ -98,6 +98,9 @@ public:
/** Renders into the GLView all the queued `RenderCommand` objects */ /** Renders into the GLView all the queued `RenderCommand` objects */
void render(); void render();
/** Cleans all `RenderCommand`s in the queue */
void clean();
/* returns the number of drawn batches in the last frame */ /* returns the number of drawn batches in the last frame */
ssize_t getDrawnBatches() const { return _drawnBatches; } ssize_t getDrawnBatches() const { return _drawnBatches; }
/* RenderCommands (except) QuadCommand should update this value */ /* RenderCommands (except) QuadCommand should update this value */

View File

@ -947,6 +947,10 @@ void VisitSceneGraph::update(float dt)
CC_PROFILER_START( this->profilerName() ); CC_PROFILER_START( this->profilerName() );
this->visit(); this->visit();
CC_PROFILER_STOP( this->profilerName() ); CC_PROFILER_STOP( this->profilerName() );
// Call `Renderer::clean` to prevent crash if current scene is destroyed.
// The render commands associated with current scene should be cleaned.
Director::getInstance()->getRenderer()->clean();
} }
std::string VisitSceneGraph::title() const std::string VisitSceneGraph::title() const