Fix crash

See bug N°244
https://qelectrotech.org/bugtracker/view.php?id=244
This commit is contained in:
joshua 2022-03-31 19:05:45 +02:00
parent 61ff8884e0
commit 5a51f6bace

View File

@ -122,8 +122,19 @@ QETProject::QETProject(KAutoSaveFile *backup, QObject *parent) :
*/
QETProject::~QETProject()
{
for (auto diagram : m_diagrams_list)
//Each time a diagram is deleted we also remove it from m_diagram_list
//because a lot of thing append during the destructor of a diagram class
//and one of these thing (not directly in the destructor of the diagram
//but in another destructor called by the diagram destructor)
//is to get the diagram list of the project to make some updates @see QList<Diagram *> QETProject::diagrams() const.
//So we need to remove the freshly deleted diagram from the list
//in each iteration of the loop to avoid the use of a dangling pointer.
const auto diag_list = m_diagrams_list;
for (const auto &diagram : diag_list)
{
delete diagram;
m_diagrams_list.removeOne(diagram);
}
}
/**