Fix crash.

When a user calls full parse and a pattern contains a lot of pieces while they
update a second call may cause a crash.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-11-14 10:52:07 +02:00
parent 8cdbb3dd7e
commit 477040c0b2
2 changed files with 28 additions and 7 deletions

View File

@ -59,6 +59,12 @@
#include "../vpatterndb/vpiecepath.h" #include "../vpatterndb/vpiecepath.h"
#include "../vpatterndb/vnodedetail.h" #include "../vpatterndb/vnodedetail.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
#include "../vmisc/backport/qscopeguard.h"
#else
#include <QScopeGuard>
#endif
#include <QMessageBox> #include <QMessageBox>
#include <QUndoStack> #include <QUndoStack>
#include <QtNumeric> #include <QtNumeric>
@ -102,7 +108,7 @@ QString DefLabelLanguage()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPattern::VPattern(VContainer *data, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, QObject *parent) VPattern::VPattern(VContainer *data, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, QObject *parent)
: VAbstractPattern(parent), data(data), sceneDraw(sceneDraw), sceneDetail(sceneDetail), updatePieces() : VAbstractPattern(parent), data(data), sceneDraw(sceneDraw), sceneDetail(sceneDetail)
{ {
SCASSERT(sceneDraw != nullptr) SCASSERT(sceneDraw != nullptr)
SCASSERT(sceneDetail != nullptr) SCASSERT(sceneDetail != nullptr)
@ -851,7 +857,7 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse
VToolSeamAllowance *piece = VToolSeamAllowance::Create(initData); VToolSeamAllowance *piece = VToolSeamAllowance::Create(initData);
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
updatePieces.append(piece); updatePieces.append(piece->getId());
} }
//Rewrite attribute formula. Need for situation when we have wrong formula. //Rewrite attribute formula. Need for situation when we have wrong formula.
if (w != initData.width) if (w != initData.width)
@ -3569,19 +3575,36 @@ quint32 VPattern::LastToolId() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPattern::RefreshPieceGeometry() void VPattern::RefreshPieceGeometry()
{ {
auto CleanRefreshList = qScopeGuard([this]()
{
updatePieces.clear();
VMainGraphicsView::NewSceneRect(sceneDetail, qApp->getSceneView());
});
if (qApp->IsGUIMode() && m_parsing) if (qApp->IsGUIMode() && m_parsing)
{ {
return; return;
} }
for(auto piece : qAsConst(updatePieces)) for(auto pieceId : qAsConst(updatePieces))
{ {
if (qApp->IsGUIMode() && m_parsing) if (qApp->IsGUIMode() && m_parsing)
{ {
return; return;
} }
piece->RefreshGeometry(); try
{
if (VToolSeamAllowance *piece = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(pieceId)))
{
piece->RefreshGeometry();
}
}
catch(const VExceptionBadId &)
{
// do nothing
}
QApplication::processEvents(); QApplication::processEvents();
if (qApp->IsGUIMode() && m_parsing) if (qApp->IsGUIMode() && m_parsing)
@ -3589,8 +3612,6 @@ void VPattern::RefreshPieceGeometry()
return; return;
} }
} }
updatePieces.clear();
VMainGraphicsView::NewSceneRect(sceneDetail, qApp->getSceneView());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -136,7 +136,7 @@ private:
VMainGraphicsScene *sceneDraw; VMainGraphicsScene *sceneDraw;
VMainGraphicsScene *sceneDetail; VMainGraphicsScene *sceneDetail;
QVector<VToolSeamAllowance *> updatePieces; QVector<vidtype> updatePieces{};
/** /**
* @brief m_parsing true if parsing a pattern. Helps to stop updating piece when new parsing happend before * @brief m_parsing true if parsing a pattern. Helps to stop updating piece when new parsing happend before