From: Soeren Apel Date: Tue, 3 Sep 2019 18:17:29 +0000 (+0200) Subject: Allow re-loading sessions to work with PD output signals X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=30cdef99af65a04ee8c55ab816044c32f7e955ad;p=pulseview.git Allow re-loading sessions to work with PD output signals --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index a3525922..9decbe30 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -370,7 +370,7 @@ void DecodeSignal::update_output_signals() dec->logic_output_channels(); // All signals of a decoder share the same LogicSegment, so it's - // sufficient to check for the first channel only + // sufficient to check for only the first channel const decode::DecoderLogicOutputChannel& first_ch = logic_channels[0]; bool ch_exists = false; @@ -380,6 +380,7 @@ void DecodeSignal::update_output_signals() if (!ch_exists) { shared_ptr logic_data = make_shared(logic_channels.size()); + logic_data->set_samplerate(first_ch.samplerate); output_logic_[dec->get_srd_decoder()] = logic_data; shared_ptr logic_segment = make_shared( @@ -1723,9 +1724,19 @@ void DecodeSignal::logic_output_callback(srd_proto_data *pdata, void *decode_sig assert(pdl); shared_ptr output_logic = ds->output_logic_.at(decc); - shared_ptr last_segment = - dynamic_pointer_cast(output_logic->segments().back()); - assert(last_segment); + + vector< shared_ptr > segments = output_logic->segments(); + + shared_ptr last_segment; + + if (!segments.empty()) + last_segment = dynamic_pointer_cast(segments.back()); + else { + // Happens when the data was cleared - all segments are gone then + last_segment = make_shared( + *output_logic, 0, (output_logic->num_channels() + 7) / 8, output_logic->get_samplerate()); + output_logic->push_segment(last_segment); + } last_segment->append_subsignal_payload(pdl->logic_class, (void*)pdl->data, pdl->size);