Skip to content

fix(ros2): move ROS2 unregistration before actor deregistration#9640

Draft
youtalk wants to merge 11 commits intocarla-simulator:ue5-devfrom
youtalk:fix/ros2-multigpu-actor-destroy
Draft

fix(ros2): move ROS2 unregistration before actor deregistration#9640
youtalk wants to merge 11 commits intocarla-simulator:ue5-devfrom
youtalk:fix/ros2-multigpu-actor-destroy

Conversation

@youtalk
Copy link
Copy Markdown
Contributor

@youtalk youtalk commented Apr 2, 2026

Description

Port multi-GPU actor destroy fix from ue4-dev 201d375d3 to ue5-dev.

Moves ROS2 UnregisterSensor/UnregisterVehicle calls inside the CarlaActor null check in OnActorDestroyed, before Registry.Deregister. This prevents a potential null pointer dereference in multi-GPU setups where CarlaActor may be null when OnActorDestroyed fires.

Also adds "actor" prefix to auto-generated ROS names for clarity.

Depends on #9638
Diff from #9638: 3f62db3

Where has this been tested?

  • Platform(s): Linux (Ubuntu 22.04)
  • Python version(s): 3.12
  • Unreal Engine version(s): 5.5 (CARLA fork)

Possible Drawbacks

  • Auto-generated ROS topic names change from <id> to actor<id> — downstream code parsing topic names may need updating

This change is Reviewable

youtalk added 9 commits April 1, 2026 19:32
Add foundational CRTP template classes for the new ROS2 publisher and
subscriber architecture, replacing the old per-sensor PIMPL pattern:

- BasePublisher.h: DDS-independent abstract base (topic, frame_id, actor)
- PublisherImpl.h: FastDDS CRTP template (DomainParticipant, Publisher,
  Topic, DataWriter, TypeSupport init/destroy/Publish)
- BaseSubscriber.h: DDS-independent abstract base for subscribers
- SubscriberImpl.h: FastDDS template (DataReader, on_data_available)

These are added alongside the existing CarlaPublisher/CarlaSubscriber
classes which will be removed in a later step.

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Introduce CarlaCameraPublisher as an abstract base class that manages
Image and CameraInfo via two PublisherImpl<T> instances. Migrate
CarlaRGBCameraPublisher to a thin subclass providing channel count and
encoding. Replace CarlaDepthCameraPublisher, CarlaNormalsCameraPublisher,
CarlaOpticalFlowCameraPublisher, CarlaSSCameraPublisher, and
CarlaISCameraPublisher with type aliases to CarlaRGBCameraPublisher,
eliminating ~2800 lines of duplicated boilerplate.

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Rewrite Clock, Collision, GNSS, IMU, Radar, Lidar, SemanticLidar, and
Transform publishers to use BasePublisher + PublisherImpl<T> templates,
replacing the old PIMPL + manual FastDDS boilerplate pattern.

Add new shared base classes:
- CarlaPointCloudPublisher: abstract base for point cloud publishers
  (LiDAR, SemanticLiDAR, DVS, Radar)
- CarlaDVSPublisher: composite publisher (Image + PointCloud) replacing
  the old CarlaDVSCameraPublisher

Delete unused publishers and old base classes:
- CarlaLineInvasionPublisher (NoopSerializer, unused)
- CarlaMapSensorPublisher (NoopSerializer, unused)
- CarlaSpeedometerSensor (unused)
- CarlaPublisher.h (replaced by BasePublisher.h)
- CarlaSubscriber.h (replaced by BaseSubscriber.h)
- CarlaDVSCameraPublisher (replaced by CarlaDVSPublisher)

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Delete CarlaListener and CarlaSubscriberListener as PublisherImpl and
SubscriberImpl now directly inherit DataWriterListener/DataReaderListener.
BasicListener is retained for the WITH_ROS2_DEMO path.

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Rewrite CarlaEgoVehicleControlSubscriber to use SubscriberImpl template,
add new AckermannControlSubscriber with AckermannDrive/AckermannDriveStamped
FastDDS types, and extend ROS2CallbackData variant with AckermannControl.

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Remove the 201d375 changes (actor prefix and unregister ordering)
from the main refactor to keep them in a separate PR.

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Update ROS2 example files from ue4-dev reference: add GNSS and IMU
sensors to stack.json configuration, update rviz config with new sensor
frames and correct lidar topic path, sync ros2_native.py with upstream,
and update README with launch instructions.

Build system (CMakeLists.txt) uses dynamic file globs so no changes
needed for renamed/added/removed source files.

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
@update-docs
Copy link
Copy Markdown

update-docs bot commented Apr 2, 2026

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would update our CHANGELOG.md based on your changes.

youtalk added 2 commits April 1, 2026 21:26
- Move ROS2.cpp compilation from LibCarla server to Ros2Native shared
  library, since publisher headers now include PublisherImpl.h which
  depends on FastDDS headers
- Add rpclib include path to Ros2Native build for MsgPack.h dependency
- Make BasicPublisher/BasicSubscriber standalone (no longer inherit
  from deleted CarlaPublisher/CarlaSubscriber base classes)
- Replace CarlaListener usage in BasicPublisher with inline
  DataWriterListener

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Move ROS2 UnregisterSensor/UnregisterVehicle calls inside the
CarlaActor null check, before Registry.Deregister. This prevents
a potential null pointer dereference in multi-GPU setups where
CarlaActor may be null when OnActorDestroyed fires.

Also add "actor" prefix to auto-generated ROS names for clarity.

Port of ue4-dev commit 201d375.

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
@youtalk youtalk force-pushed the fix/ros2-multigpu-actor-destroy branch from 3f62db3 to 0eb0e90 Compare April 2, 2026 04:27
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