]> sigrok.org Git - pulseview.git/blobdiff - pv/session.cpp
Fix #775 by catching and handling the thrown exception
[pulseview.git] / pv / session.cpp
index 0fef9c91764bc75366bc8db57cfd6880783465b3..c18f809446a037475f4106e10576f3a89d5c1688 100644 (file)
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifdef _WIN32
-// Windows: Avoid boost/thread namespace pollution (which includes windows.h).
-#define NOGDI
-#define NORESOURCE
-#endif
-
 #include <QFileInfo>
 
 #include <cassert>
+#include <memory>
 #include <mutex>
 #include <stdexcept>
 
 #include <sys/stat.h>
 
-#include "session.hpp"
 #include "devicemanager.hpp"
+#include "session.hpp"
 
 #include "data/analog.hpp"
 #include "data/analogsegment.hpp"
+#include "data/decode/decoder.hpp"
 #include "data/decoderstack.hpp"
 #include "data/logic.hpp"
 #include "data/logicsegment.hpp"
 #include "data/signalbase.hpp"
-#include "data/decode/decoder.hpp"
 
 #include "devices/hardwaredevice.hpp"
 #include "devices/inputfile.hpp"
@@ -77,6 +72,7 @@ using std::recursive_mutex;
 using std::runtime_error;
 using std::shared_ptr;
 using std::string;
+using std::unique_ptr;
 using std::unordered_set;
 using std::vector;
 
@@ -810,7 +806,7 @@ void Session::update_signals()
                                        }
 
                                        default:
-                                               assert(0);
+                                               assert(false);
                                                break;
                                        }
                                }
@@ -853,13 +849,20 @@ void Session::sample_thread_proc(function<void (const QString)> error_handler)
        set_capture_state(device_->session()->trigger() ?
                AwaitingTrigger : Running);
 
-       device_->run();
+       try {
+               device_->run();
+       } catch (Error e) {
+               error_handler(e.what());
+               set_capture_state(Stopped);
+               return;
+       }
+
        set_capture_state(Stopped);
 
        // Confirm that SR_DF_END was received
        if (cur_logic_segment_) {
                qDebug("SR_DF_END was not received.");
-               assert(0);
+               assert(false);
        }
 
        // Optimize memory usage
@@ -981,12 +984,15 @@ void Session::feed_in_analog(shared_ptr<Analog> analog)
        const vector<shared_ptr<Channel>> channels = analog->channels();
        const unsigned int channel_count = channels.size();
        const size_t sample_count = analog->num_samples() / channel_count;
-       const float *data = static_cast<const float *>(analog->data_pointer());
        bool sweep_beginning = false;
 
+       unique_ptr<float> data(new float[analog->num_samples()]);
+       analog->get_data_as_float(data.get());
+
        if (signalbases_.empty())
                update_signals();
 
+       float *channel_data = data.get();
        for (auto channel : channels) {
                shared_ptr<data::AnalogSegment> segment;
 
@@ -1020,7 +1026,7 @@ void Session::feed_in_analog(shared_ptr<Analog> analog)
                assert(segment);
 
                // Append the samples in the segment
-               segment->append_interleaved_samples(data++, sample_count,
+               segment->append_interleaved_samples(channel_data++, sample_count,
                        channel_count);
        }
 
@@ -1035,7 +1041,7 @@ void Session::feed_in_analog(shared_ptr<Analog> analog)
 void Session::data_feed_in(shared_ptr<sigrok::Device> device,
        shared_ptr<Packet> packet)
 {
-       static bool frame_began=false;
+       static bool frame_began = false;
 
        (void)device;