diff --git a/src/plugins/topic_viewer/TopicViewer.cc b/src/plugins/topic_viewer/TopicViewer.cc index 4e7ee8b3a..7e95a79c1 100644 --- a/src/plugins/topic_viewer/TopicViewer.cc +++ b/src/plugins/topic_viewer/TopicViewer.cc @@ -388,11 +388,19 @@ void TopicViewer::UpdateModel() std::vector publishers; std::vector subscribers; this->dataPtr->node.TopicInfo(topics[i], publishers, subscribers); + + if (publishers.empty()) + continue; + + // ToDo: Go over all the publishers and also consider subscribers. + // Review the way we're using "topicsToRemove" as the logic doesn't look + // very clear to me. + std::string msgType = publishers[0].MsgTypeName(); // skip the matched topics if (this->dataPtr->currentTopics.count(topics[i]) && - this->dataPtr->currentTopics[topics[i]] == msgType) + this->dataPtr->currentTopics[topics[i]] == msgType) { topicsToRemove.erase(topics[i]); continue; @@ -413,7 +421,7 @@ void TopicViewer::UpdateModel() auto child = root->child(i); if (child->data(NAME_ROLE).toString().toStdString() == topic.first && - child->data(TYPE_ROLE).toString().toStdString() == topic.second) + child->data(TYPE_ROLE).toString().toStdString() == topic.second) { // remove from model root->removeRow(i);