Skip to content

Commit

Permalink
fix iterator erase-read conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
zeddie888 committed Oct 22, 2023
1 parent 9ddbed2 commit bebab20
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,22 @@ const Catalog &CatalogRead() {
char *tsvPath = getenv("LOST_BSC_PATH");
catalog = BscParse(tsvPath ? tsvPath : DEFAULT_BSC_PATH);
// perform essential narrowing
// remove all stars with exactly the same position as another, keeping the one with brighter magnitude
// remove all stars with exactly the same position as another, keeping the one with brighter
// magnitude
std::sort(catalog.begin(), catalog.end(), [](const CatalogStar &a, const CatalogStar &b) {
return a.spatial.x < b.spatial.x;
if (a.spatial.x != b.spatial.x) {
return a.spatial.x < b.spatial.x;
} else if (a.spatial.y != b.spatial.y) {
return a.spatial.y < b.spatial.y;
}
return a.spatial.z < b.spatial.z;
});
for (int i = catalog.size()-1; i > 0; i--) { // [BUG]? catalog[catalog.size()] is invalid
if ((catalog[i].spatial - catalog[i-1].spatial).Magnitude() < 5e-5) { // 70 stars removed at this threshold.
if (catalog[i].magnitude > catalog[i-1].magnitude) {
// [BUG]? If mag of i > mag of i-1, we want to keep i? Here we remove i
for (int i = catalog.size() - 1; i > 0; i--) { // [BUG]? catalog[catalog.size()] is invalid
if ((catalog[i].spatial - catalog[i - 1].spatial).Magnitude() < 5e-5) { // 70 stars removed at this threshold.
if (catalog[i].magnitude > catalog[i - 1].magnitude) {
// [BUG]? If mag of i > mag of i-1, we want to keep i, not i-1
catalog.erase(catalog.begin() + i - 1);
i--;
} else {
catalog.erase(catalog.begin() + i);
}
Expand Down

0 comments on commit bebab20

Please sign in to comment.