Handle some malformed mpd files. Fixes #533.

- Skip duplicate submodels
- Skip recursive includes
This commit is contained in:
Leonardo Zide 2020-11-25 19:54:32 -08:00
parent f386de205d
commit 462897caf7
2 changed files with 21 additions and 3 deletions

View file

@ -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;
}

View file

@ -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<int, lcModel*>& 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;