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_;
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;
}
}
cur_samplerate_ = device_->read_config<uint64_t>(ConfigKey::SAMPLERATE);
+ out_of_memory_ = false;
+
try {
device_->start();
} catch(Error e) {
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()
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: