Fixed crash after open broken file. Now program will show error message.

--HG--
branch : develop
This commit is contained in:
dismine 2014-10-30 14:52:49 +02:00
parent 8407f714a5
commit 2bfff3f592
3 changed files with 30 additions and 20 deletions

View File

@ -2258,6 +2258,8 @@ void MainWindow::LoadPattern(const QString &fileName)
FullParseFile(); FullParseFile();
if (guiEnabled)
{ // No errors occurred
bool patternModified = this->isWindowModified(); bool patternModified = this->isWindowModified();
setCurrentFile(fileName); setCurrentFile(fileName);
if (patternModified) if (patternModified)
@ -2271,6 +2273,7 @@ void MainWindow::LoadPattern(const QString &fileName)
//Fit scene size to best size for first show //Fit scene size to best size for first show
ZoomFirstShow(); ZoomFirstShow();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -366,16 +366,18 @@ void VPattern::Parse(const Document &parse)
*/ */
VDataTool *VPattern::getTool(const quint32 &id) VDataTool *VPattern::getTool(const quint32 &id)
{ {
if (tools.contains(id)) ToolExists(id);
{
return tools.value(id); return tools.value(id);
} }
else
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ToolExists(const quint32 &id) const
{
if (tools.contains(id) == false)
{ {
const QString error = QString(tr("Can't find tool id = %1 in table.")).arg(id); throw VExceptionBadId(tr("Can't find tool in table."), id);
throw VException(error);
} }
return 0;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -430,6 +432,7 @@ void VPattern::setCurrentData()
} }
if (tools.size() > 0) if (tools.size() > 0)
{ {
ToolExists(id);
const VDataTool *vTool = tools.value(id); const VDataTool *vTool = tools.value(id);
*data = vTool->getData(); *data = vTool->getData();
} }
@ -460,6 +463,7 @@ void VPattern::UpdateToolData(const quint32 &id, VContainer *data)
{ {
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
SCASSERT(data != nullptr); SCASSERT(data != nullptr);
ToolExists(id);
VDataTool *tool = tools.value(id); VDataTool *tool = tools.value(id);
SCASSERT(tool != nullptr); SCASSERT(tool != nullptr);
tool->VDataTool::setData(data); tool->VDataTool::setData(data);
@ -473,6 +477,7 @@ void VPattern::UpdateToolData(const quint32 &id, VContainer *data)
void VPattern::IncrementReferens(quint32 id) const void VPattern::IncrementReferens(quint32 id) const
{ {
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
ToolExists(id);
VDataTool *tool = tools.value(id); VDataTool *tool = tools.value(id);
SCASSERT(tool != nullptr); SCASSERT(tool != nullptr);
tool->incrementReferens(); tool->incrementReferens();
@ -486,6 +491,7 @@ void VPattern::IncrementReferens(quint32 id) const
void VPattern::DecrementReferens(quint32 id) const void VPattern::DecrementReferens(quint32 id) const
{ {
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
ToolExists(id);
VDataTool *tool = tools.value(id); VDataTool *tool = tools.value(id);
SCASSERT(tool != nullptr); SCASSERT(tool != nullptr);
tool->decrementReferens(); tool->decrementReferens();

View File

@ -285,6 +285,7 @@ private:
void ParseCurrentPP(); void ParseCurrentPP();
void CheckTagExists(const QString &tag); void CheckTagExists(const QString &tag);
QString GetLabelBase(unsigned int index)const; QString GetLabelBase(unsigned int index)const;
void ToolExists(const quint32 &id) const;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------