From 462897caf7a1ecc9293f03370cc9486d7a55faae Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Wed, 25 Nov 2020 19:54:32 -0800 Subject: [PATCH] Handle some malformed mpd files. Fixes #533. - Skip duplicate submodels - Skip recursive includes --- common/lc_model.cpp | 8 ++++++++ common/project.cpp | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 493897a1..e852380f 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -734,6 +734,14 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project) Piece->SetColorCode(ColorCode); Piece->VerifyControlPoints(ControlPoints); Piece->SetControlPoints(ControlPoints); + + if (Piece->mPieceInfo->IsModel() && Piece->mPieceInfo->GetModel()->IncludesModel(this)) + { + delete Piece; + Piece = nullptr; + continue; + } + AddPiece(Piece); Piece = nullptr; } diff --git a/common/project.cpp b/common/project.cpp index 27459b76..43ec0b26 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -401,9 +401,19 @@ bool Project::Load(const QString& FileName) if (Models.empty() || !Model->GetFileName().isEmpty()) { - mModels.Add(Model); - Models.emplace_back(std::make_pair(Pos, Model)); - Model->CreatePieceInfo(this); + auto ModelCompare = [Model](const std::pair& ModelIt) + { + return ModelIt.second->GetFileName() == Model->GetFileName(); + }; + + if (std::find_if(Models.begin(), Models.end(), ModelCompare) == Models.end()) + { + mModels.Add(Model); + Models.emplace_back(std::make_pair(Pos, Model)); + Model->CreatePieceInfo(this); + } + else + delete Model; } else delete Model;