Commit 15b5a0ff authored by Frédéric Larue's avatar Frédéric Larue
Browse files

Memory leaks due to Qt plugins unloading fixed.

parent e3912b7b
......@@ -81,6 +81,14 @@ void AlgorithmSelector::populateTools( ToolInterface *plugin )
}
void AlgorithmSelector::releaseAllTools()
{
for( auto &category : m_ToolsByCategory )
for( auto &tool : category )
delete tool.param;
}
void AlgorithmSelector::finalizeTools()
{
// Sort tools by name for each category.
......
......@@ -54,6 +54,7 @@ public:
~AlgorithmSelector();
void populateTools( ToolInterface *tool );
void releaseAllTools();
void finalizeTools();
inline QString currentToolName() const { return m_SelectedTool->plugin->name( m_SelectedTool->id ); }
......
......@@ -97,15 +97,17 @@ void UIMainWindow::init()
void UIMainWindow::release()
{
delete ui;
if( m_CurrentViewer )
m_CurrentViewer->removeAllDisplayables();
closeAllProjects();
for(QList<QPluginLoader*>::iterator p = m_plugins.begin() ; p != m_plugins.end() ; ++p)
delete *p;
ui->toolSelector->releaseAllTools();
delete ui;
unloadPlugins();
//for(QList<QPluginLoader*>::iterator p = m_plugins.begin() ; p != m_plugins.end() ; ++p)
// delete *p;
}
......@@ -146,7 +148,7 @@ void UIMainWindow::loadPlugins()
{
QPluginLoader* loader = new QPluginLoader( pluginsDir.absoluteFilePath(fileName) );
if(!loader->load())
if( !loader->load() )
{
delete loader;
}
......@@ -156,7 +158,8 @@ void UIMainWindow::loadPlugins()
if( plugin )
{
m_plugins.push_back(loader);
m_pluginLoaders.push_back( loader );
m_plugins.push_back( plugin );
ToolInterface *tool = qobject_cast<ToolInterface*>( plugin );
if( tool )
......@@ -204,6 +207,29 @@ void UIMainWindow::loadPlugins()
}
bool UIMainWindow::unloadPlugins()
{
bool ok = true;
for( auto p : m_plugins )
delete p;
for( QList<QPluginLoader*>::iterator p=m_pluginLoaders.begin(); p!=m_pluginLoaders.end(); )
if( (*p)->unload() )
{
delete *p;
p = m_pluginLoaders.erase( p );
}
else
{
ok = false;
++ p;
}
return ok;
}
QList<GenericUIData*> UIMainWindow::selection()
{
return ui->tableCurrentProjContent->selectedData();
......@@ -644,7 +670,7 @@ void UIMainWindow::displayPluginsList()
// Populate categories w/ plugins
for(QList<QPluginLoader*>::iterator p = m_plugins.begin() ; p != m_plugins.end() ; ++p)
for(QList<QPluginLoader*>::iterator p = m_pluginLoaders.begin() ; p != m_pluginLoaders.end() ; ++p)
{
QObject *plugin = (*p)->instance();
......
......@@ -26,6 +26,7 @@ class ImportInterface;
class UIParamSet;
class PhaseIdentifier;
namespace Ui
{
class MainWindow;
......@@ -50,8 +51,9 @@ class GUIMAIN_API UIMainWindow : public QMainWindow
UIProject *m_CurrentProject;
GLViewer *m_CurrentViewer;
QList<QPluginLoader*> m_plugins;
QList<QPluginLoader*> m_pluginLoaders;
QList<QObject*> m_plugins;
QList<DisplayableFactoryInterface*> m_DisplayablePlugins;
QList<ImportHandle> m_ImportPlugins;
QMap<QString,ImportHandle> m_ImportSortedByExtensions;
......@@ -95,6 +97,7 @@ private:
void setMainWindowTitleInfos( const QString& str );
void loadPlugins();
bool unloadPlugins();
void importFiles( const QStringList& selectedFiles );
void loadProject( const QString& filename );
......
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