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 Feb 23, 2023
1 parent d2dff1a commit e03feb1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 22 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
8 changes: 8 additions & 0 deletions test/integration/boundingbox_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ void BoundingBoxCameraSensorTest::BoxesWithBuiltinSDF(

g_mutex.unlock();

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

// Clean up
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
rendering::unloadEngine(engine->Name());
}
Expand Down Expand Up @@ -465,7 +469,11 @@ void BoundingBoxCameraSensorTest::Boxes3DWithBuiltinSDF(

g_mutex.unlock();

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

// Clean up
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
rendering::unloadEngine(engine->Name());
}
Expand Down
12 changes: 6 additions & 6 deletions test/integration/depth_camera.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 @@ -336,11 +337,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(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0;
Expand Down Expand Up @@ -372,11 +371,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(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0;
Expand Down Expand Up @@ -408,11 +405,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(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0;
Expand Down Expand Up @@ -497,7 +492,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.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,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 @@ -416,8 +417,11 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine)
EXPECT_FALSE(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 @@ -573,7 +577,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 @@ -693,7 +704,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 @@ -819,8 +834,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 @@ -859,7 +878,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.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 @@ -529,11 +530,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(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0; sleep < 300 &&
Expand Down Expand Up @@ -635,11 +634,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(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0; sleep < 300 &&
Expand Down Expand Up @@ -740,7 +737,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
4 changes: 4 additions & 0 deletions test/integration/segmentation_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ void SegmentationCameraSensorTest::ImagesWithBuiltinSDF(
}
}

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

// Clean up
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
ignition::rendering::unloadEngine(engine->Name());
}
Expand Down
16 changes: 8 additions & 8 deletions test/integration/thermal_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,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(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0;
Expand Down Expand Up @@ -316,11 +314,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(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0;
Expand Down Expand Up @@ -352,7 +348,11 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
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 Expand Up @@ -543,11 +543,9 @@ void ThermalCameraSensorTest::Images8BitWithBuiltinSDF(
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(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0;
Expand Down Expand Up @@ -578,11 +576,9 @@ void ThermalCameraSensorTest::Images8BitWithBuiltinSDF(
g_mutex.unlock();

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

mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
for (int sleep = 0;
Expand Down Expand Up @@ -614,7 +610,11 @@ void ThermalCameraSensorTest::Images8BitWithBuiltinSDF(
delete [] g_thermalBuffer8Bit;
g_thermalBuffer8Bit = 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 e03feb1

Please sign in to comment.