Skip to content

Commit

Permalink
Add entity validation to OdometryPublisher (#2326)
Browse files Browse the repository at this point in the history
Until SystemManager has the ability to unload system plugins, plugins require an explicit check of the validity of the entities used in the Update methods. Such a check was missing in OdometryPublisher, which led to non-critical but annoying errors in the console.
---------

Signed-off-by: Anton Bogdanov <[email protected]>
  • Loading branch information
Bogdanov Anton authored Mar 1, 2024
1 parent 633ce72 commit 1349900
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/systems/odometry_publisher/OdometryPublisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ void OdometryPublisher::PreUpdate(const gz::sim::UpdateInfo &_info,
{
GZ_PROFILE("OdometryPublisher::PreUpdate");

// \TODO(anyone) This is a temporary fix for
// gazebosim/gz-sim#2165 until gazebosim/gz-sim#2217 is resolved.
if (kNullEntity == this->dataPtr->model.Entity())
{
return;
}

if (!this->dataPtr->model.Valid(_ecm))
{
gzwarn << "OdometryPublisher model no longer valid. "
<< "Disabling plugin." << std::endl;
this->dataPtr->model = Model(kNullEntity);
return;
}

// \TODO(anyone) Support rewind
if (_info.dt < std::chrono::steady_clock::duration::zero())
{
Expand All @@ -301,6 +316,15 @@ void OdometryPublisher::PostUpdate(const UpdateInfo &_info,
const EntityComponentManager &_ecm)
{
GZ_PROFILE("OdometryPublisher::PostUpdate");

// \TODO(anyone) This is a temporary fix for
// gazebosim/gz-sim#2165 until gazebosim/gz-sim#2217 is resolved.
if (kNullEntity == this->dataPtr->model.Entity())
{
return;
}


// Nothing left to do if paused.
if (_info.paused)
return;
Expand Down

0 comments on commit 1349900

Please sign in to comment.