]> sigrok.org Git - pulseview.git/commitdiff
Fix #626 by stopping acquisition gracefully
authorSoeren Apel <redacted>
Wed, 19 Aug 2015 19:34:11 +0000 (21:34 +0200)
committerSoeren Apel <redacted>
Wed, 19 Aug 2015 19:34:11 +0000 (21:34 +0200)
pv/data/analogsegment.cpp
pv/data/segment.cpp
pv/session.cpp
pv/session.hpp

index c1a119e4cd13305f3caa91f98c6a420ab918d927..3703f0d02780e13f86ffc962e93beadea1c5a1ce 100644 (file)
@@ -69,6 +69,7 @@ void AnalogSegment::append_interleaved_samples(const float *data,
 
        lock_guard<recursive_mutex> lock(mutex_);
 
+       // If we're out of memory, this will throw std::bad_alloc
        data_.resize((sample_count_ + sample_count) * sizeof(float));
 
        float *dst = (float*)data_.data() + sample_count_;
index 111b62b71aadf0c43189540050c55e92de29dc43..bc08fd07917564d86e13f35f3d37ad20dcae64e9 100644 (file)
@@ -78,8 +78,9 @@ void Segment::set_capacity(const uint64_t new_capacity)
 
        assert(capacity_ >= sample_count_);
        if (new_capacity > capacity_) {
-               capacity_ = new_capacity;
+               // If we're out of memory, this will throw std::bad_alloc
                data_.resize((new_capacity * unit_size_) + sizeof(uint64_t));
+               capacity_ = new_capacity;
        }
 }
 
index 56ac89975f65e97c47d4f28a2de96142b4f6316d..22e0428d94abf26a5421c540377dc9e55c6ddccf 100644 (file)
@@ -419,6 +419,8 @@ void Session::sample_thread_proc(shared_ptr<devices::Device> device,
 
        cur_samplerate_ = device_->read_config<uint64_t>(ConfigKey::SAMPLERATE);
 
+       out_of_memory_ = false;
+
        try {
                device_->start();
        } catch(Error e) {
@@ -438,6 +440,9 @@ void Session::sample_thread_proc(shared_ptr<devices::Device> device,
                qDebug("SR_DF_END was not received.");
                assert(0);
        }
+
+       if (out_of_memory_)
+               error_handler(tr("Out of memory, acquisition stopped."));
 }
 
 void Session::feed_in_header()
@@ -590,11 +595,21 @@ void Session::data_feed_in(shared_ptr<sigrok::Device> device,
                break;
 
        case SR_DF_LOGIC:
-               feed_in_logic(dynamic_pointer_cast<Logic>(packet->payload()));
+               try {
+                       feed_in_logic(dynamic_pointer_cast<Logic>(packet->payload()));
+               } catch (std::bad_alloc) {
+                       out_of_memory_ = true;
+                       device_->stop();
+               }
                break;
 
        case SR_DF_ANALOG:
-               feed_in_analog(dynamic_pointer_cast<Analog>(packet->payload()));
+               try {
+                       feed_in_analog(dynamic_pointer_cast<Analog>(packet->payload()));
+               } catch (std::bad_alloc) {
+                       out_of_memory_ = true;
+                       device_->stop();
+               }
                break;
 
        case SR_DF_END:
index 59060a591fdfd0d743ad83780dbcd066cdefbc01..3d303da47f198a6b3f88d046298126b4d5453270 100644 (file)
@@ -174,6 +174,8 @@ private:
 
        std::thread sampling_thread_;
 
+       bool out_of_memory_;
+
 Q_SIGNALS:
        void capture_state_changed(int state);
        void device_selected();