Skip to content

Made it possible to initialize LiDARSensor later so that it works with the built app. #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

hijimasa
Copy link
Contributor

In the previous version, the simulation was executed after the LiDARSensor settings were completed in the editor, and the Init function was called. However, in the built app, the Init function was called before the settings were made, resulting in a NullReferenceException. To ensure that the app works in the built version as well, I modified the code so that if an element is null, it is not initialized immediately but can be initialized later.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the initialization logic for the LiDAR sensor components so that sensors can be initialized later in the built app without triggering exceptions.

  • LiDARPointCloud2MsgPublisher now checks for a null source and logs an error before aborting initialization.
  • RaycastLiDARSensor and DepthBufferLiDARSensor have been modified to check for a null scanPattern before executing initialization, delegating further logic to an overridden Initialize method.
  • LiDARSensor now provides a virtual Initialize method that clamps sensor parameters and configures point cloud data only when the scanPattern is available.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs Added null check for _source to prevent a NullReferenceException.
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs Switched to a deferred initialization pattern by checking scanPattern and overriding Initialize.
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/LiDARSensor.cs Modified Init to delay initialization when _scanPattern is not available and introduced Initialize.
Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs Applied a similar deferred initialization approach as with RaycastLiDARSensor.

RyodoTanaka and others added 3 commits April 29, 2025 20:05
…ointCloud2Msg/LiDARPointCloud2MsgPublisher.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…iDAR/DepthBufferLiDARSensor.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…/RaycastLiDARSensor.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@RyodoTanaka RyodoTanaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
I will merge it.

@RyodoTanaka RyodoTanaka merged commit 71ad0ff into Field-Robotics-Japan:master Apr 29, 2025
0 of 2 checks passed
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.

2 participants