Skip to content

Commit

Permalink
clean up rendering resources (#324)
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 97b6123 commit 48195de
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/RenderingSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ RenderingSensor::RenderingSensor() :
//////////////////////////////////////////////////
RenderingSensor::~RenderingSensor()
{
if (!this->dataPtr->scene)
if (!this->dataPtr->scene || !this->dataPtr->scene->IsInitialized())
return;
for (auto &s : this->dataPtr->sensors)
{
Expand Down
12 changes: 6 additions & 6 deletions test/integration/depth_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
box->SetLocalRotation(0, 0, 0);
box->SetLocalScale(unitBoxSize, unitBoxSize, unitBoxSize);
box->SetMaterial(blue);
scene->DestroyMaterial(blue);
root->AddChild(box);

// do the test
Expand Down Expand Up @@ -333,11 +334,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
EXPECT_EQ(9, infoMsg.rectification_matrix().size());

// Check that for a box really close it returns -inf
root->RemoveChild(box);
gz::math::Vector3d boxPositionNear(
unitBoxSize * 0.5 + near_ * 0.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionNear);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -369,11 +368,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
g_mutex.unlock();

// Check that for a box really far it returns inf
root->RemoveChild(box);
gz::math::Vector3d boxPositionFar(
unitBoxSize * 0.5 + far_ * 1.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionFar);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -405,11 +402,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(


// Check that the depth values for a box do not warp.
root->RemoveChild(box);
gz::math::Vector3d boxPositionFillFrame(
unitBoxSize * 0.5 + 0.2, 0.0, 0.0);
box->SetLocalPosition(boxPositionFillFrame);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -494,7 +489,12 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
g_mutex.unlock();
g_pcMutex.unlock();

// clean up rendering ptrs
blue.reset();
box.reset();

// Clean up
mgr.Remove(depthSensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down
24 changes: 21 additions & 3 deletions test/integration/gpu_lidar_sensor_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ void GpuLidarSensorTest::CreateGpuLidar(const std::string &_renderEngine)

// Clean up
c.reset();
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -414,8 +415,11 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine)
EXPECT_TRUE(pointMsgs.back().is_dense());
EXPECT_EQ(32u * horzSamples * vertSamples, pointMsgs.back().data().size());

// Clean up rendering ptrs
visualBox1.reset();

// Clean up
//
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -567,7 +571,14 @@ void GpuLidarSensorTest::TestThreeBoxes(const std::string &_renderEngine)
for (unsigned int i = 0; i < sensor1->RayCount(); ++i)
EXPECT_DOUBLE_EQ(sensor2->Range(i), gz::math::INF_D);

// Clean up rendering ptrs
visualBox1.reset();
visualBox2.reset();
visualBox3.reset();

// Clean up
mgr.Remove(sensor1->Id());
mgr.Remove(sensor2->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -687,7 +698,11 @@ void GpuLidarSensorTest::VerticalLidar(const std::string &_renderEngine)
}
}

// Clean up rendering ptrs
visualBox1.reset();

// Clean up
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -809,8 +824,12 @@ void GpuLidarSensorTest::ManualUpdate(const std::string &_renderEngine)
EXPECT_DOUBLE_EQ(sensor2->Range(last), gz::math::INF_D);
#endif

// Clean up rendering ptrs
visualBox1.reset();

// Clean up
//
mgr.Remove(sensor1->Id());
mgr.Remove(sensor2->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -849,7 +868,6 @@ void GpuLidarSensorTest::Topic(const std::string &_renderEngine)
// Create a GpuLidarSensor
gz::sensors::Manager mgr;


// Default topic
{
const std::string topic;
Expand Down
10 changes: 6 additions & 4 deletions test/integration/rgbd_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
box->SetLocalRotation(0, 0, 0);
box->SetLocalScale(unitBoxSize, unitBoxSize, unitBoxSize);
box->SetMaterial(blue);
scene->DestroyMaterial(blue);
root->AddChild(box);

// do the test
Expand Down Expand Up @@ -526,11 +527,9 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
g_imgMutex.unlock();

// Check that for a box really close it returns -inf
root->RemoveChild(box);
math::Vector3d boxPositionNear(
unitBoxSize * 0.5 + near_ * 0.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionNear);
root->AddChild(box);

mgr.RunOnce(common::Time::Zero, true);
for (int sleep = 0; sleep < 300 &&
Expand Down Expand Up @@ -632,11 +631,9 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
g_pcMutex.unlock();

// Check that for a box really far it returns inf
root->RemoveChild(box);
math::Vector3d boxPositionFar(
unitBoxSize * 0.5 + far_ * 1.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionFar);
root->AddChild(box);

mgr.RunOnce(common::Time::Zero, true);
for (int sleep = 0; sleep < 300 &&
Expand Down Expand Up @@ -737,7 +734,12 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
g_imgMutex.unlock();
g_pcMutex.unlock();

// Clean up rendering ptrs
box.reset();
blue.reset();

// Clean up
mgr.Remove(rgbdSensor->Id());
engine->DestroyScene(scene);
rendering::unloadEngine(engine->Name());
}
Expand Down
10 changes: 6 additions & 4 deletions test/integration/thermal_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,9 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
EXPECT_EQ(9, infoMsg.rectification_matrix().size());

// Check that for a box really close it returns box temperature
root->RemoveChild(box);
gz::math::Vector3d boxPositionNear(
unitBoxSize * 0.5 + near_ * 0.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionNear);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -296,11 +294,9 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
g_mutex.unlock();

// Check that for a box really far it returns ambient temperature
root->RemoveChild(box);
gz::math::Vector3d boxPositionFar(
unitBoxSize * 0.5 + far_ * 1.5, 0.0, 0.0);
box->SetLocalPosition(boxPositionFar);
root->AddChild(box);

mgr.RunOnce(gz::common::Time::Zero, true);
for (int sleep = 0;
Expand Down Expand Up @@ -329,8 +325,14 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
g_infoMutex.unlock();
g_mutex.unlock();

delete [] g_thermalBuffer;
g_thermalBuffer = nullptr;

// Clean up rendering ptrs
box.reset();

// Clean up
mgr.Remove(thermalSensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}
Expand Down

0 comments on commit 48195de

Please sign in to comment.