From e93c2fd67bf015883109672d224fdb270cb31ce1 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 1 Mar 2005 02:50:23 +0000 Subject: [PATCH] fix leaked ActorFrame children --- stepmania/src/ActorFrame.cpp | 50 ++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/stepmania/src/ActorFrame.cpp b/stepmania/src/ActorFrame.cpp index ce6d56314b..19ecfbe964 100644 --- a/stepmania/src/ActorFrame.cpp +++ b/stepmania/src/ActorFrame.cpp @@ -12,7 +12,40 @@ // lua start LUA_REGISTER_CLASS( ActorFrame ) // lua end -REGISTER_ACTOR_CLASS( ActorFrame ) + +/* Tricky: We need ActorFrames created in XML to auto delete their children. + * We don't want classes that derive from ActorFrame to auto delete their + * children. The name "ActorFrame" is widely used in XML, so we'll have + * that string instead create an ActorFrameAutoDeleteChildren object. + */ +//REGISTER_ACTOR_CLASS( ActorFrame ) +class ActorFrameAutoDeleteChildren : public ActorFrame +{ +public: + ActorFrameAutoDeleteChildren() { DeleteChildrenWhenDone(true); } + void LoadFromNode( const CString& sDir, const XNode* pNode ) + { + ActorFrame::LoadFromNode( sDir, pNode ); + + // + // Load children + // + const XNode* pChildren = pNode->GetChild("children"); + if( pChildren ) + { + FOREACH_CONST_Child( pChildren, pChild ) + { + Actor* pChildActor = ActorUtil::LoadFromActorFile( sDir, pChild ); + if( pChildActor ) + AddChild( pChildActor ); + } + SortByDrawOrder(); + } + } + +}; +REGISTER_ACTOR_CLASS_WITH_NAME( ActorFrameAutoDeleteChildren, ActorFrame ) + ActorFrame::ActorFrame() { @@ -37,21 +70,6 @@ void ActorFrame::LoadFromNode( const CString& sDir, const XNode* pNode ) pNode->GetAttrValue( "UpdateRate", m_fUpdateRate ); pNode->GetAttrValue( "FOV", m_fFOV ); m_bOverrideLighting = pNode->GetAttrValue( "Lighting", m_bLighting ); - - // - // Load children - // - const XNode* pChildren = pNode->GetChild("children"); - if( pChildren ) - { - FOREACH_CONST_Child( pChildren, pChild ) - { - Actor* pChildActor = ActorUtil::LoadFromActorFile( sDir, pChild ); - if( pChildActor ) - AddChild( pChildActor ); - } - SortByDrawOrder(); - } } void ActorFrame::AddChild( Actor* pActor )