From 9e6718974230135af5719a25bfb62c559dd17ed4 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Mon, 1 Apr 2024 11:10:17 +0800 Subject: [PATCH] fix: search the decoded data crashed sometimes --- DSView/pv/data/decode/rowdata.cpp | 6 ++- DSView/pv/data/decode/rowdata.h | 2 +- DSView/pv/data/decodermodel.cpp | 5 +- DSView/pv/data/decoderstack.cpp | 2 +- DSView/pv/data/decoderstack.h | 2 +- DSView/pv/dock/protocoldock.cpp | 77 ++++++++++++++++++++----------- 6 files changed, 59 insertions(+), 35 deletions(-) diff --git a/DSView/pv/data/decode/rowdata.cpp b/DSView/pv/data/decode/rowdata.cpp index dc4d0a02..08690e62 100644 --- a/DSView/pv/data/decode/rowdata.cpp +++ b/DSView/pv/data/decode/rowdata.cpp @@ -138,12 +138,14 @@ bool RowData::push_annotation(Annotation *a) } -bool RowData::get_annotation(Annotation &ann, uint64_t index) +bool RowData::get_annotation(Annotation *ann, uint64_t index) { + assert(ann); + std::lock_guard lock(_global_visitor_mutex); if (index < _annotations.size()) { - ann = *_annotations[index]; + *ann = *_annotations[index]; //clone return true; } else { return false; diff --git a/DSView/pv/data/decode/rowdata.h b/DSView/pv/data/decode/rowdata.h index 8314eb6b..feb0ee44 100644 --- a/DSView/pv/data/decode/rowdata.h +++ b/DSView/pv/data/decode/rowdata.h @@ -52,7 +52,7 @@ public: return _item_count; } - bool get_annotation(pv::data::decode::Annotation &ann, uint64_t index); + bool get_annotation(pv::data::decode::Annotation *ann, uint64_t index); /** * Extracts sorted annotations between two period into a vector. diff --git a/DSView/pv/data/decodermodel.cpp b/DSView/pv/data/decodermodel.cpp index af62d7b9..61710e54 100644 --- a/DSView/pv/data/decodermodel.cpp +++ b/DSView/pv/data/decodermodel.cpp @@ -67,10 +67,11 @@ QVariant DecoderModel::data(const QModelIndex &index, int role) const if (role == Qt::TextAlignmentRole) { return int(Qt::AlignLeft | Qt::AlignVCenter); - } else if (role == Qt::DisplayRole) { + } + else if (role == Qt::DisplayRole) { if (_decoder_stack) { pv::data::decode::Annotation ann; - if (_decoder_stack->list_annotation(ann, index.column(), index.row())) { + if (_decoder_stack->list_annotation(&ann, index.column(), index.row())) { return ann.annotations().at(0); } } diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index aa42f5c8..623f5d8f 100644 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -333,7 +333,7 @@ uint64_t DecoderStack::list_annotation_size(uint16_t row_index) return 0; } -bool DecoderStack::list_annotation(pv::data::decode::Annotation &ann, +bool DecoderStack::list_annotation(pv::data::decode::Annotation *ann, uint16_t row_index, uint64_t col_index) { for (auto i = _rows.begin(); i != _rows.end(); i++) { diff --git a/DSView/pv/data/decoderstack.h b/DSView/pv/data/decoderstack.h index 89428386..9b8de2f0 100644 --- a/DSView/pv/data/decoderstack.h +++ b/DSView/pv/data/decoderstack.h @@ -127,7 +127,7 @@ public: uint64_t list_annotation_size(uint16_t row_index); - bool list_annotation(decode::Annotation &ann, + bool list_annotation(decode::Annotation *ann, uint16_t row_index, uint64_t col_index); diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index b9ba7fe2..636ad0e6 100644 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -546,9 +546,10 @@ void ProtocolDock::item_clicked(const QModelIndex &index) pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); auto decoder_stack = decoder_model->getDecoderStack(); + if (decoder_stack) { pv::data::decode::Annotation ann; - if (decoder_stack->list_annotation(ann, index.column(), index.row())) { + if (decoder_stack->list_annotation(&ann, index.column(), index.row())) { const auto &decode_sigs = _session->get_decode_signals(); for(auto d : decode_sigs) { @@ -559,6 +560,7 @@ void ProtocolDock::item_clicked(const QModelIndex &index) _session->show_region(ann.start_sample(), ann.end_sample(), false); } } + _table_view->resizeRowToContents(index.row()); if (index.column() != _model_proxy.filterKeyColumn()) { _model_proxy.setFilterKeyColumn(index.column()); @@ -638,20 +640,26 @@ void ProtocolDock::nav_table_view() } } QModelIndex index = _model_proxy.mapToSource(_model_proxy.index(row_index, _model_proxy.filterKeyColumn())); - if(index.isValid()){ - _table_view->scrollTo(index); - _table_view->setCurrentIndex(index); + + if(index.isValid()){ pv::data::decode::Annotation ann; - decoder_stack->list_annotation(ann, index.column(), index.row()); - const auto &decode_sigs = _session->get_decode_signals(); - for(auto d : decode_sigs) { - d->decoder()->set_mark_index(-1); - } - decoder_stack->set_mark_index((ann.start_sample()+ann.end_sample())/2); - _view.set_all_update(true); - _view.update(); + if (decoder_stack->list_annotation(&ann, index.column(), index.row())) + { + _table_view->scrollTo(index); + _table_view->setCurrentIndex(index); + + const auto &decode_sigs = _session->get_decode_signals(); + + for(auto d : decode_sigs) { + d->decoder()->set_mark_index(-1); + } + + decoder_stack->set_mark_index((ann.start_sample()+ann.end_sample())/2); + _view.set_all_update(true); + _view.update(); + } } } } @@ -686,22 +694,30 @@ void ProtocolDock::search_pre() uint64_t row = matchingIndex.row() + 1; uint64_t col = matchingIndex.column(); pv::data::decode::Annotation ann; - bool ann_valid; + bool ann_valid = false; + while(i < _str_list.size()) { QString nxt = _str_list.at(i); do { - ann_valid = decoder_stack->list_annotation(ann, col, row); + ann_valid = decoder_stack->list_annotation(&ann, col, row); row++; - }while(ann_valid && !ann.is_numberic()); + } + while(ann_valid && !ann.is_numberic()); - QString source = ann.annotations().at(0); - if (ann_valid && source.contains(nxt)) - i++; - else + if (ann_valid){ + QString source = ann.annotations().at(0); + if (source.contains(nxt)) + i++; + else + break; + } + else{ break; + } } - }while(i < _str_list.size() && --rowCount); + } + while(i < _str_list.size() && --rowCount); if(i >= _str_list.size() && matchingIndex.isValid()){ _table_view->scrollTo(matchingIndex); @@ -753,22 +769,27 @@ void ProtocolDock::search_nxt() uint64_t row = matchingIndex.row() + 1; uint64_t col = matchingIndex.column(); pv::data::decode::Annotation ann; - bool ann_valid; + bool ann_valid = false; while(i < _str_list.size()) { QString nxt = _str_list.at(i); do { - ann_valid = decoder_stack->list_annotation(ann, col, row); + ann_valid = decoder_stack->list_annotation(&ann, col, row); row++; - }while(ann_valid && !ann.is_numberic()); + } + while(ann_valid && !ann.is_numberic()); - auto strlist = ann.annotations(); - QString source = ann.annotations().at(0); - if (ann_valid && source.contains(nxt)) - i++; - else + if (ann_valid){ + QString source = ann.annotations().at(0); + if (source.contains(nxt)) + i++; + else + break; + } + else{ break; + } } }while(i < _str_list.size() && --rowCount);