]> sigrok.org Git - pulseview.git/commitdiff
DeviceManager: Prevent PV crashes when scanning for devices
authorSoeren Apel <redacted>
Wed, 24 Oct 2018 20:08:13 +0000 (22:08 +0200)
committerUwe Hermann <redacted>
Wed, 24 Oct 2018 22:08:42 +0000 (00:08 +0200)
pv/devicemanager.cpp

index ebf140fd725c793f340e089cbb49d412a0348297..5090b480e3d49adc41bc4e861102ce9a6e6bbb8b 100644 (file)
@@ -30,6 +30,7 @@
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
 #include <QApplication>
+#include <QDebug>
 #include <QObject>
 #include <QProgressDialog>
 
@@ -252,21 +253,27 @@ DeviceManager::driver_scan(
        devices_.remove_if([&](shared_ptr<devices::HardwareDevice> device) {
                return device->hardware_device()->driver() == driver; });
 
-       // Do the scan
-       auto devices = driver->scan(drvopts);
+       try {
+               // Do the scan
+               auto devices = driver->scan(drvopts);
 
-       // Add the scanned devices to the main list, set display names and sort.
-       for (shared_ptr<sigrok::HardwareDevice>& device : devices) {
-               const shared_ptr<devices::HardwareDevice> d(
-                       new devices::HardwareDevice(context_, device));
-               driver_devices.push_back(d);
-       }
+               // Add the scanned devices to the main list, set display names and sort.
+               for (shared_ptr<sigrok::HardwareDevice>& device : devices) {
+                       const shared_ptr<devices::HardwareDevice> d(
+                               new devices::HardwareDevice(context_, device));
+                       driver_devices.push_back(d);
+               }
 
-       devices_.insert(devices_.end(), driver_devices.begin(),
-               driver_devices.end());
-       devices_.sort(bind(&DeviceManager::compare_devices, this, _1, _2));
-       driver_devices.sort(bind(
-               &DeviceManager::compare_devices, this, _1, _2));
+               devices_.insert(devices_.end(), driver_devices.begin(),
+                       driver_devices.end());
+               devices_.sort(bind(&DeviceManager::compare_devices, this, _1, _2));
+               driver_devices.sort(bind(
+                       &DeviceManager::compare_devices, this, _1, _2));
+
+       } catch (const sigrok::Error &e) {
+               qWarning() << QApplication::tr("Error when scanning device driver '%1': %2").
+                       arg(QString::fromStdString(driver->name()), e.what());
+       }
 
        return driver_devices;
 }