Fix crashes in median() if all spans in a level are short (#1668)

master
jie 2020-06-02 02:29:37 -07:00 committed by GitHub
parent 02594a07c7
commit 47b80c9a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -188,8 +188,13 @@ std::vector<Floor> FindFloors(const proto::Trajectory& trajectory,
common::FromUniversal(
trajectory.node(span.end_index - 1).timestamp())});
}
std::sort(z_values.begin(), z_values.end());
floors.back().z = Median(z_values);
if (!z_values.empty()) {
std::sort(z_values.begin(), z_values.end());
floors.back().z = Median(z_values);
} else {
LOG(ERROR) << "All spans in level are short";
floors.pop_back();
}
}
return floors;
}