]> git.sesse.net Git - vlc/commitdiff
skins2: improve deallocation of ressources for layouts and controls
authorErwan Tulou <erwan10@videolan.org>
Thu, 14 Jan 2010 13:34:48 +0000 (14:34 +0100)
committerErwan Tulou <erwan10@videolan.org>
Thu, 14 Jan 2010 14:24:04 +0000 (15:24 +0100)
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.

modules/gui/skins2/controls/ctrl_button.cpp
modules/gui/skins2/controls/ctrl_button.hpp
modules/gui/skins2/controls/ctrl_generic.cpp
modules/gui/skins2/controls/ctrl_generic.hpp
modules/gui/skins2/controls/ctrl_move.cpp
modules/gui/skins2/controls/ctrl_move.hpp
modules/gui/skins2/controls/ctrl_resize.cpp
modules/gui/skins2/controls/ctrl_resize.hpp
modules/gui/skins2/controls/ctrl_video.cpp
modules/gui/skins2/controls/ctrl_video.hpp
modules/gui/skins2/src/generic_layout.cpp

index 071b0ffe46f45977c23c5a4df0882c754317c73c..a1eb12559a6f0f576e57cebc775b68c91e100f43 100644 (file)
@@ -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() );
index f1ef77eb2b0c17dd3c170603cdbb79461a08fe97..6e4581a8c983fbd47a8f0006a2e61df822f7ef8b 100644 (file)
@@ -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 );
index 77e0e8e90180022ae60d0a005dbae024076871b6..81465feebf03da90ec843597fd3d80d61c02f0dc 100644 (file)
@@ -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
index 886c27b3d9c7146d2f6318392f211e1bc29ac4c7..d1decf734f1bfb83110929063107a72c219567ca 100644 (file)
@@ -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; }
index e890d16e47a5cea427fce8a805807d687d3776d9..f4cf8880fdb7b3c07d27183357d41fe728ac133a 100644 (file)
@@ -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();
index 5a4f958b1aa81a15bdab7222a5a7da8716c8e286..67e813fe2bd9103c783721bfdb57985045daf471 100644 (file)
@@ -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;
index 5cd70702f80377a9ae3cb1285aa6a8b7ccc47d6a..1fb37b72bf9ffe6c7aaccbf067c7f52686d59418 100644 (file)
@@ -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();
index f540773f3144ab3b75ba676bbd92da6a427fc555..7d2d718b1819b059e9371fb7663c2d7a8e44aacb 100644 (file)
@@ -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;
index 68c8e4c477811bbe6afd02eb5dd43e7aef06575f..484feb84afc56366c13f65ae03417b04bee77100 100644 (file)
@@ -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 =
index 9afd7038d49600e82de71be066e8f34c16a9cc3a..570bd1c34161a0c923813a1c6df7021734e3cd11 100644 (file)
@@ -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 );
index 8b353713dd9437219626cf8602de6dab40cc6166..217d3b0ba8df2abeed116ec47f41a0c1d4a87bee 100644 (file)
@@ -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();
+    }
+
 }