diff -r 50f055543ff6 -r 8a3047468994 src/model.h --- a/src/model.h Wed Mar 09 12:42:45 2022 +0200 +++ b/src/model.h Wed Mar 09 13:01:50 2022 +0200 @@ -68,7 +68,8 @@ private: bool modified = false; std::vector body; - std::map objectsById; + mutable std::map objectsById; + mutable bool needObjectsByIdRebuild = false; }; void save(const Model& model, QIODevice *device); @@ -99,7 +100,7 @@ Q_EMIT beginInsertRows({}, position, position); this->body.push_back(std::make_unique(args...)); ldraw::Object* pointer = this->body.back().get(); - this->objectsById[pointer->id] = pointer; + this->objectsById[pointer->id] = this->body.size() - 1; Q_EMIT endInsertRows(); return ldraw::Id{pointer->id.value}; } @@ -110,7 +111,7 @@ Q_EMIT beginInsertRows({}, position, position); this->body.insert(std::begin(this->body) + position, std::make_unique(args...)); ldraw::Object* pointer = this->body[position].get(); - this->objectsById[pointer->id] = pointer; + this->objectsById[pointer->id] = position; Q_EMIT endInsertRows(); return ldraw::Id{pointer->id.value}; }