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 <QImage>
#include <QDir> #include <QDir>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QThreadPool>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutGenerator::VLayoutGenerator(QObject *parent) VLayoutGenerator::VLayoutGenerator(QObject *parent)
@ -183,6 +184,9 @@ void VLayoutGenerator::Abort()
{ {
stopGeneration = true; stopGeneration = true;
state = LayoutErrors::ProcessStoped; 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; VBestSquare bestResult;
QThreadPool *thread_pool = QThreadPool::globalInstance(); QThreadPool *thread_pool = QThreadPool::globalInstance();
thread_pool->setExpiryTimeout(1000);
QVector<VPosition *> threads; QVector<VPosition *> threads;
for (int j=1; j <= d->globalContour.EdgesCount(); ++j) for (int j=1; j <= d->globalContour.EdgesCount(); ++j)
{ {
for (int i=1; i<= detail.EdgesCount(); i++) 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); VPosition *thread = new VPosition(d->globalContour, j, detail, i, &stop, d->rotate, d->rotationIncrease);
//Info for debug //Info for debug
@ -208,15 +209,14 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop)
} }
} }
if (thread_pool->waitForDone() == false) thread_pool->waitForDone();
{
return false;
}
QCoreApplication::processEvents(); QCoreApplication::processEvents();
if (stop) if (stop)
{ {
qDeleteAll(threads.begin(), threads.end());
threads.clear();
return false; return false;
} }

View File

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