Skip to content

Fix coordinate transform, border, matching, intersection, and store bugs & perf in ad_map_access - #264

Open
M-Colley wants to merge 1 commit into
carla-simulator:mainfrom
M-Colley:fix/ad-map-access-core-bugs-and-perf
Open

M-Colley wants to merge 1 commit into
carla-simulator:mainfrom
M-Colley:fix/ad-map-access-core-bugs-and-perf

Conversation

@M-Colley

@M-Colley M-Colley commented Nov 14, 2026 •

Copy link
Copy Markdown

Summary

Fixes memory leaks, thread-safety bugs, geometric singularities, serialization bounds, border alignment folds, map-matching/restriction logic errors, and algorithmic bottlenecks across ad_map_access core modules.

Note: Part 3 of 5 independent, modular PRs branched directly from main with strictly disjoint file sets (each builds, tests, and merges cleanly in any order).

Bug Fixes

  • CoordinateTransform & Point/Geometry Operations:
    • Free PJ * handle in ~CoordinateTransform(), implement rule-of-five copy/move semantics, make instance_counter_ atomic, wrap antimeridian longitude deltas in Geo2ENU and GeoOperation::isOnTheLeft, and guard polar / near-origin singularities in ECEF2Geo.
    • Add extern to explicit template instantiation declarations in ECEFOperation.hpp and ENUOperation.hpp.
    • Guard empty edges, zero-length segments, degenerate cross products in createECEFHeading, right-edge point validation in calculateWidthRange, and synchronize ENUCache access.
  • Access, Config & Serialization:
    • Cap untrusted deserialized container reservations (ISerializer.hpp, StoreSerialization.cpp), close Serializer on version mismatch, check fclose() in StorageFile, fix GeometryStore uninitialized singleton lookup and geometric buffer growth overflow, erase all matching contacts in Factory::deleteContacts, and validate config GeoPoint bounds and path prefixes in MapConfigFileHandler.
  • OpenDRIVE Conversion, Lane, Match, Landmark, Restriction & Intersection:
    • Guard empty geometry unsigned underflow in AdMapFactory, preserve signal subType, and parse multi-digit speed limits in DataTypeConversion.
    • Rewrite BorderOperation::fillSmallerEdge with monotonic anchor-to-anchor interpolation (preventing OOB reads and backward edge folds).
    • Add missing throw in getContactLanes, guard cyclic lateral contacts in projectPositionToLaneInHeadingDirection, fix swapped left/right edges in MapMatchedOperation::getENUBorder and bounds-check reference_point_positions, support LandmarkId(0) in uniqueLandmarkId, conjunctively combine conjunctions and disjunctions in RestrictionOperation::isAccessOk, fix AdMapMatching::getHeadingFactor range and single-lane findRouteLanes probability, and make CoreIntersection traversals cycle-safe and BIDIRECTIONAL-aware.

Performance Improvements

  • Eliminate deep copies of Lane, Landmark, Geometry, and point edges across Store, Factory, LaneOperation, CoreIntersection, Intersection, and AdMapMatching, and avoid $O(N^2)$ landmark scans in Factory::add.
  • Replace $O(M^2)$ scans in getLateralAlignmentEdge and getMiddleEdge with $O(M + N)$ two-pointer sweeps, pre-index route-hint lane IDs in AdMapMatching, and avoid redundant corner map-matching in getMapMatchedBoundingBox.

Tests

  • Added unit regression tests across FactoryTests.cpp, LandmarkOperationTests.cpp, LaneOperationTests.cpp, AdMapBoundingBoxMapMatchingTest.cpp, AdMapMatchingTests.cpp, CoordinateTransformTests.cpp, GeoOperationTests.cpp, and PointOperationTests.cpp.

This change is Reviewable

Bug fixes:
- CoordinateTransform: free PROJ handle in destructor, implement rule-of-five
  copy/move operations, make instance_counter_ atomic, wrap antimeridian
  longitude delta in Geo2ENU, and guard pole/near-origin singularities in
  ECEF2Geo.
- Point & Geometry operations: declare explicit template instantiations as
  extern in ECEFOperation.hpp and ENUOperation.hpp, guard empty edges and
  zero-length denominators in EdgeOperation.hpp and GeometryOperation.cpp,
  validate edge_right points in calculateWidthRange, wrap antimeridian
  longitude deltas in GeoOperation::isOnTheLeft, guard degenerate cross
  products in createECEFHeading, and add thread-safe ENUCache synchronization.
- Access, Config & Serialization: cap deserialized container allocations,
  fix GeometryStore contact lookup against uninitialized singleton store and
  cap geometric growth, erase all matching contacts in Factory::deleteContacts,
  avoid O(N^2) landmark scans in Factory::add, close Serializer on version
  mismatch, check fclose() return in StorageFile, and validate parsed config
  GeoPoints and path prefixes in MapConfigFileHandler.
- OpenDRIVE conversion: avoid unsigned underflow on empty geometry in
  AdMapFactory, preserve signal subType parsing, and handle multi-digit speed
  limit strings in DataTypeConversion.
- Lane, Border, Match, Landmark, Restriction & Intersection: rewrite
  fillSmallerEdge with monotonic anchor-to-anchor interpolation (fixing OOB
  reads and backward folds), add missing throw in getContactLanes, guard
  cyclic lateral contacts in projectPositionToLaneInHeadingDirection, fix
  swapped left/right edges in MapMatchedOperation::getENUBorder and bounds-check
  reference_point_positions, support LandmarkId(0) in uniqueLandmarkId,
  conjunctively combine conjunctions and disjunctions in
  RestrictionOperation::isAccessOk, fix AdMapMatching::getHeadingFactor range
  and single-lane findRouteLanes probability, and make CoreIntersection graph
  traversals cycle-safe and BIDIRECTIONAL-aware.

Performance optimizations:
- Avoid deep copies of Lane, Landmark, Geometry, and point vectors across
  Store, Factory, LaneOperation, CoreIntersection, Intersection, and
  AdMapMatching.
- Replace O(M^2) getLateralAlignmentEdge and getMiddleEdge scans with O(M + N)
  two-pointer sweeps, cache route-hint lane IDs in AdMapMatching, and skip
  redundant corner map-matching in getMapMatchedBoundingBox.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant