Commit 63304ea5 authored by Erwan Tulou's avatar Erwan Tulou

skins2: improve deallocation of ressources for layouts and controls

Layouts and Controls are interrelated. Whatever the ones first deallocated, it leaves pointers referencing objects already destroyed. and potentially means memory leak.

This patch adds an unsetLayout() function to pair the setLayout() function and aimed at releasing resources.
Policy should now be that things allocated in constructor are released in destructor and things allocated in setLayout are released in unsetLayout.
parent bd179ee7
......@@ -89,6 +89,12 @@ void CtrlButton::setLayout( GenericLayout *pLayout,
}
void CtrlButton::unsetLayout()
{
m_pLayout->getActiveVar().delObserver( this );
CtrlGeneric::unsetLayout();
}
void CtrlButton::handleEvent( EvtGeneric &rEvent )
{
m_fsm.handleTransition( rEvent.getAsString() );
......
......@@ -48,6 +48,7 @@ public:
/// Set the position and the associated layout of the control
virtual void setLayout( GenericLayout *pLayout,
const Position &rPosition );
virtual void unsetLayout();
/// Handle an event
virtual void handleEvent( EvtGeneric &rEvent );
......
......@@ -29,6 +29,8 @@
#include "../utils/position.hpp"
#include "../utils/var_bool.hpp"
#include <assert.h>
CtrlGeneric::CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
VarBool *pVisible):
......@@ -45,7 +47,6 @@ CtrlGeneric::CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
CtrlGeneric::~CtrlGeneric()
{
delete m_pPosition;
if( m_pVisible )
{
m_pVisible->delObserver( this );
......@@ -56,12 +57,21 @@ CtrlGeneric::~CtrlGeneric()
void CtrlGeneric::setLayout( GenericLayout *pLayout,
const Position &rPosition )
{
assert( !m_pLayout && pLayout);
m_pLayout = pLayout;
delete m_pPosition;
m_pPosition = new Position( rPosition );
onPositionChange();
}
void CtrlGeneric::unsetLayout()
{
assert( m_pLayout );
delete m_pPosition;
m_pPosition = NULL;
m_pLayout = NULL;
}
void CtrlGeneric::notifyLayout( int width, int height,
int xOffSet, int yOffSet ) const
......
......@@ -58,6 +58,7 @@ public:
/// Set the position and the associated layout of the control
virtual void setLayout( GenericLayout *pLayout,
const Position &rPosition );
virtual void unsetLayout();
/// Get the position of the control in the layout, if any
virtual const Position *getPosition() const { return m_pPosition; }
......
......@@ -80,6 +80,13 @@ void CtrlMove::setLayout( GenericLayout *pLayout, const Position &rPosition )
}
void CtrlMove::unsetLayout( )
{
m_rCtrl.unsetLayout();
CtrlGeneric::unsetLayout();
}
const Position *CtrlMove::getPosition() const
{
return m_rCtrl.getPosition();
......
......@@ -54,6 +54,7 @@ public:
/// Set the position and the associated layout of the decorated control
virtual void setLayout( GenericLayout *pLayout,
const Position &rPosition );
virtual void unsetLayout( );
/// Get the position of the decorated control in the layout, if any
virtual const Position *getPosition() const;
......
......@@ -89,6 +89,13 @@ void CtrlResize::setLayout( GenericLayout *pLayout, const Position &rPosition )
}
void CtrlResize::unsetLayout()
{
m_rCtrl.unsetLayout();
CtrlGeneric::unsetLayout();
}
const Position *CtrlResize::getPosition() const
{
return m_rCtrl.getPosition();
......
......@@ -55,6 +55,7 @@ public:
/// Set the position and the associated layout of the decorated control
virtual void setLayout( GenericLayout *pLayout,
const Position &rPosition );
virtual void unsetLayout();
/// Get the position of the decorated control in the layout, if any
virtual const Position *getPosition() const;
......
......@@ -48,8 +48,6 @@ CtrlVideo::~CtrlVideo()
{
VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
rFullscreen.delObserver( this );
//m_pLayout->getActiveVar().delObserver( this );
}
......@@ -111,6 +109,13 @@ void CtrlVideo::setLayout( GenericLayout *pLayout,
}
void CtrlVideo::unsetLayout()
{
m_pLayout->getActiveVar().delObserver( this );
CtrlGeneric::unsetLayout();
}
void CtrlVideo::resizeControl( int width, int height )
{
WindowManager &rWindowManager =
......
......@@ -78,6 +78,7 @@ public:
/// Set the position and the associated layout of the control
virtual void setLayout( GenericLayout *pLayout,
const Position &rPosition );
virtual void unsetLayout();
// resize the video Control
virtual void resizeControl( int width, int height );
......
......@@ -56,11 +56,20 @@ GenericLayout::GenericLayout( intf_thread_t *pIntf, int width, int height,
GenericLayout::~GenericLayout()
{
delete m_pImage;
list<Anchor*>::const_iterator it;
for( it = m_anchorList.begin(); it != m_anchorList.end(); it++ )
{
delete *it;
}
list<LayeredControl>::const_iterator iter;
for( iter = m_controlList.begin(); iter != m_controlList.end(); iter++ )
{
CtrlGeneric *pCtrl = (*iter).m_pControl;
pCtrl->unsetLayout();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment