From 76152906bea3c76281d63cf6cbb774a5f9d635b2 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 10 Mar 2016 15:37:38 -0800 Subject: [PATCH] Fix crash bug in asset manager --- .../src/AssetMappingsScriptingInterface.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp b/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp index ee8deb4056..77cc435fb8 100644 --- a/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp +++ b/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp @@ -155,13 +155,13 @@ void AssetMappingModel::refresh() { auto it = _pathToItemMap.find(fullPath); if (it == _pathToItemMap.end()) { - qDebug() << "prefix not found: " << fullPath; auto item = new QStandardItem(parts[i]); bool isFolder = i < length - 1; item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole); item->setData(isFolder, Qt::UserRole + 1); item->setData(parts[i], Qt::UserRole + 2); item->setData("atp:" + fullPath, Qt::UserRole + 3); + item->setData(fullPath, Qt::UserRole + 4); if (lastItem) { lastItem->setChild(lastItem->rowCount(), 0, item); } else { @@ -182,6 +182,7 @@ void AssetMappingModel::refresh() { // Remove folders from list auto it = existingPaths.begin(); while (it != existingPaths.end()) { + Q_ASSERT(_pathToItemMap.contains(*it)); auto item = _pathToItemMap[*it]; if (item->data(Qt::UserRole + 1).toBool()) { it = existingPaths.erase(it); @@ -192,7 +193,6 @@ void AssetMappingModel::refresh() { for (auto& path : existingPaths) { Q_ASSERT(_pathToItemMap.contains(path)); - qDebug() << "removing existing: " << path; auto item = _pathToItemMap[path]; @@ -200,6 +200,7 @@ void AssetMappingModel::refresh() { // During each iteration, delete item QStandardItem* nextItem = nullptr; + auto fullPath = item->data(Qt::UserRole + 4).toString(); auto parent = item->parent(); if (parent) { parent->removeRow(item->row()); @@ -210,15 +211,15 @@ void AssetMappingModel::refresh() { nextItem = parent; } } else { - removeRow(item->row()); + auto removed = removeRow(item->row()); + Q_ASSERT(removed); } - _pathToItemMap.remove(path); - //delete item; + Q_ASSERT(_pathToItemMap.contains(fullPath)); + _pathToItemMap.remove(fullPath); item = nextItem; } - //removeitem->index(); } } else { emit errorGettingMappings(uint8_t(request->getError()));