Fix #928 by catching errors if config_list() fails
[pulseview.git] / pv / toolbars / mainbar.cpp
index 1879693d57a31c01bc87458f556d67dd01db7506..0bb4c4541cc704f50420c06324ec0fa9de83686c 100644 (file)
@@ -313,7 +313,11 @@ void MainBar::update_sample_rate_selector()
        const shared_ptr<sigrok::Device> sr_dev = device->device();
 
        if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
-               gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
+               try {
+                       gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
+               } catch (Error error) {
+                       qDebug() << tr("Failed to get sample rate list:") << error.what();
+               }
        } else {
                sample_rate_.show_none();
                updating_sample_rate_ = false;
@@ -413,10 +417,14 @@ void MainBar::update_sample_count_selector()
        }
 
        if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::LIST)) {
-               auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
-               if (gvar.gobj())
-                       g_variant_get(gvar.gobj(), "(tt)",
-                               &min_sample_count, &max_sample_count);
+               try {
+                       auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
+                       if (gvar.gobj())
+                               g_variant_get(gvar.gobj(), "(tt)",
+                                       &min_sample_count, &max_sample_count);
+               } catch (Error error) {
+                       qDebug() << tr("Failed to get sample limit list:") << error.what();
+               }
        }
 
        min_sample_count = min(max(min_sample_count, MinSampleCount),
@@ -612,6 +620,13 @@ void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
                const uint64_t end_sample = (uint64_t)max(
                        (double)0, end_time.convert_to<double>() * samplerate);
 
+               if ((start_sample == 0) && (end_sample == 0)) {
+                       // Both cursors are negative and were clamped to 0
+                       show_session_error(tr("Invalid Range"), tr("The cursors don't " \
+                                       "define a valid range of samples."));
+                       return;
+               }
+
                sample_range = make_pair(start_sample, end_sample);
        } else {
                sample_range = make_pair(0, 0);