From 9b7da3e071e1b17554f6be9bc9311b06e1196a14 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 5 Jan 2019 23:17:20 +0100 Subject: [PATCH] Attempt to fix crashes in devices --- src/device/devicemanager.cpp | 3 +++ src/device/deviceview.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/device/devicemanager.cpp b/src/device/devicemanager.cpp index 19c97a8b..5ffc2913 100644 --- a/src/device/devicemanager.cpp +++ b/src/device/devicemanager.cpp @@ -542,6 +542,8 @@ std::shared_ptr DeviceManager::Connect(int row) { } info->device_ = ret; QModelIndex index = ItemToIndex(info); + if (!index.isValid()) return ret; + emit dataChanged(index, index); connect(info->device_.get(), SIGNAL(TaskStarted(int)), SLOT(DeviceTaskStarted(int))); connect(info->device_.get(), SIGNAL(SongCountUpdated(int)), SLOT(DeviceSongCountUpdated(int))); @@ -639,6 +641,7 @@ void DeviceManager::DeviceTaskStarted(int id) { DeviceInfo *info = devices_[i]; if (info->device_.get() == device) { QModelIndex index = ItemToIndex(info); + if (!index.isValid()) continue; active_tasks_[id] = index; info->task_percentage_ = 0; emit dataChanged(index, index); diff --git a/src/device/deviceview.cpp b/src/device/deviceview.cpp index 6355ef39..0032ed49 100644 --- a/src/device/deviceview.cpp +++ b/src/device/deviceview.cpp @@ -308,8 +308,11 @@ void DeviceView::DeviceConnected(int row) { if (!device) return; DeviceInfo *info = app_->device_manager()->ItemFromRow(row); + if (!info) return; QModelIndex index = app_->device_manager()->ItemToIndex(info); + if (!index.isValid()) return; QModelIndex sort_idx = sort_model_->mapFromSource(index); + if (!sort_idx.isValid()) return; QSortFilterProxyModel *sort_model = new QSortFilterProxyModel(device->model()); sort_model->setSourceModel(device->model()); @@ -326,6 +329,7 @@ void DeviceView::DeviceDisconnected(int row) { DeviceInfo *info = app_->device_manager()->ItemFromRow(row); if (!info) return; QModelIndex index = app_->device_manager()->ItemToIndex(info); + if (!index.isValid()) return; merged_model_->RemoveSubModel(sort_model_->mapFromSource(index)); }