Skip to content

Commit

Permalink
Destroy rendering sensors when sensor is removed (#169)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored and scpeters committed Oct 16, 2023
1 parent 3ace7ae commit 97b6123
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/RenderingSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ RenderingSensor::RenderingSensor() :
//////////////////////////////////////////////////
RenderingSensor::~RenderingSensor()
{
if (!this->dataPtr->scene)
return;
for (auto &s : this->dataPtr->sensors)
{
auto sensor = s.lock();
if (sensor)
this->dataPtr->scene->DestroySensor(sensor);
}
this->dataPtr->sensors.clear();
}

/////////////////////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions test/integration/camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ void CameraSensorTest::ImagesWithBuiltinSDF(const std::string &_renderEngine)
EXPECT_DOUBLE_EQ(0.0, projection.p(11));
}

// test removing sensor
// first make sure the sensor objects do exist
auto sensorId = sensor->Id();
auto cameraId = sensor->RenderingCamera()->Id();
EXPECT_EQ(sensor, mgr.Sensor(sensorId));
EXPECT_EQ(sensor->RenderingCamera(), scene->SensorById(cameraId));
// remove and check sensor objects no longer exist in both sensors and
// rendering
EXPECT_TRUE(mgr.Remove(sensorId));
EXPECT_EQ(nullptr, mgr.Sensor(sensorId));
EXPECT_EQ(nullptr, scene->SensorById(cameraId));

// Clean up
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
Expand Down

0 comments on commit 97b6123

Please sign in to comment.