Memory leak. Quick stop creation a layout.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-05-02 20:18:31 +03:00
parent 5766523733
commit 6ce904d652
3 changed files with 11 additions and 7 deletions

View File

@ -34,6 +34,7 @@
#include <QImage>
#include <QDir>
#include <QGraphicsItem>
#include <QThreadPool>
//---------------------------------------------------------------------------------------------------------------------
VLayoutGenerator::VLayoutGenerator(QObject *parent)
@ -183,6 +184,9 @@ void VLayoutGenerator::Abort()
{
stopGeneration = true;
state = LayoutErrors::ProcessStoped;
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
QThreadPool::globalInstance()->clear();
#endif
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -183,13 +183,14 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop)
{
VBestSquare bestResult;
QThreadPool *thread_pool = QThreadPool::globalInstance();
thread_pool->setExpiryTimeout(1000);
QVector<VPosition *> threads;
for (int j=1; j <= d->globalContour.EdgesCount(); ++j)
{
for (int i=1; i<= detail.EdgesCount(); i++)
{
QCoreApplication::processEvents();
//QCoreApplication::processEvents();
VPosition *thread = new VPosition(d->globalContour, j, detail, i, &stop, d->rotate, d->rotationIncrease);
//Info for debug
@ -208,15 +209,14 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop)
}
}
if (thread_pool->waitForDone() == false)
{
return false;
}
thread_pool->waitForDone();
QCoreApplication::processEvents();
if (stop)
{
qDeleteAll(threads.begin(), threads.end());
threads.clear();
return false;
}

View File

@ -58,13 +58,13 @@ VPosition::VPosition(const VContour &gContour, int j, const VLayoutDetail &detai
//---------------------------------------------------------------------------------------------------------------------
void VPosition::run()
{
QCoreApplication::processEvents();
if (*stop)
{
return;
}
QCoreApplication::processEvents();
// We should use copy of the detail.
VLayoutDetail workDetail = detail;