Fix crash bug in asset manager

This commit is contained in:
Ryan Huffman 2016-03-10 15:37:38 -08:00
parent c93ba2752b
commit 76152906be

View file

@ -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()));