Skip to content

Commit a3121bd

Browse files
authored
Small Fix for Reloading Tree from #61 (#96)
* Add missing err:out_of_range code-sections + intent fixes * Revert "Add missing err:out_of_range code-sections + intent fixes" This reverts commit fa8a75b. * indentation fixes * indentation fixes - again * get node status out of try/catch for compiler * main thing: move rest of uid-based logic in try/catch for reload
1 parent 65d9265 commit a3121bd

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

bt_editor/sidepanel_monitor.cpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,60 +48,60 @@ void SidepanelMonitor::on_timer()
4848

4949
const uint32_t header_size = flatbuffers::ReadScalar<uint32_t>( buffer );
5050
const uint32_t num_transitions = flatbuffers::ReadScalar<uint32_t>( &buffer[4+header_size] );
51-
52-
// check uid in the index, if failed load tree from server
53-
try {
54-
for(size_t offset = 4; offset < header_size +4; offset +=3 )
55-
{
56-
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset]);
57-
_uid_to_index.at(uid);
58-
}
59-
60-
for(size_t t=0; t < num_transitions; t++)
61-
{
62-
size_t offset = 8 + header_size + 12*t;
63-
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset+8]);
64-
_uid_to_index.at(uid);
65-
}
66-
}
67-
catch( std::out_of_range& err) {
68-
qDebug() << "Reload tree from server";
69-
if( !getTreeFromServer() ) {
70-
_connected = false;
71-
ui->lineEdit->setDisabled(false);
72-
_timer->stop();
73-
connectionUpdate(false);
74-
return;
75-
}
76-
}
77-
78-
for(size_t offset = 4; offset < header_size +4; offset +=3 )
79-
{
80-
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset]);
81-
const uint16_t index = _uid_to_index.at(uid);
82-
AbstractTreeNode* node = _loaded_tree.node( index );
83-
node->status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[offset+2] ));
84-
}
85-
51+
8652
std::vector<std::pair<int, NodeStatus>> node_status;
53+
// check uid in the index, if failed load tree from server
54+
try{
55+
for(size_t offset = 4; offset < header_size +4; offset +=3 )
56+
{
57+
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset]);
58+
_uid_to_index.at(uid);
59+
}
60+
61+
for(size_t t=0; t < num_transitions; t++)
62+
{
63+
size_t offset = 8 + header_size + 12*t;
64+
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset+8]);
65+
_uid_to_index.at(uid);
66+
}
8767

88-
//qDebug() << "--------";
89-
for(size_t t=0; t < num_transitions; t++)
90-
{
91-
size_t offset = 8 + header_size + 12*t;
68+
for(size_t offset = 4; offset < header_size +4; offset +=3 )
69+
{
70+
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset]);
71+
const uint16_t index = _uid_to_index.at(uid);
72+
AbstractTreeNode* node = _loaded_tree.node( index );
73+
node->status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[offset+2] ));
74+
}
9275

93-
// const double t_sec = flatbuffers::ReadScalar<uint32_t>( &buffer[offset] );
94-
// const double t_usec = flatbuffers::ReadScalar<uint32_t>( &buffer[offset+4] );
95-
// double timestamp = t_sec + t_usec* 0.000001;
96-
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset+8]);
97-
const uint16_t index = _uid_to_index.at(uid);
98-
// NodeStatus prev_status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[index+10] ));
99-
NodeStatus status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[offset+11] ));
76+
//qDebug() << "--------";
77+
for(size_t t=0; t < num_transitions; t++)
78+
{
79+
size_t offset = 8 + header_size + 12*t;
10080

101-
_loaded_tree.node(index)->status = status;
102-
node_status.push_back( {index, status} );
81+
// const double t_sec = flatbuffers::ReadScalar<uint32_t>( &buffer[offset] );
82+
// const double t_usec = flatbuffers::ReadScalar<uint32_t>( &buffer[offset+4] );
83+
// double timestamp = t_sec + t_usec* 0.000001;
84+
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset+8]);
85+
const uint16_t index = _uid_to_index.at(uid);
86+
// NodeStatus prev_status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[index+10] ));
87+
NodeStatus status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[offset+11] ));
10388

89+
_loaded_tree.node(index)->status = status;
90+
node_status.push_back( {index, status} );
91+
92+
}
10493
}
94+
catch( std::out_of_range& err) {
95+
qDebug() << "Reload tree from server";
96+
if( !getTreeFromServer() ) {
97+
_connected = false;
98+
ui->lineEdit->setDisabled(false);
99+
_timer->stop();
100+
connectionUpdate(false);
101+
return;
102+
}
103+
}
104+
105105
// update the graphic part
106106
emit changeNodeStyle( "BehaviorTree", node_status );
107107
}

0 commit comments

Comments
 (0)