Skip to content

Commit e03feb1

Browse files
authored
clean up rendering resources (#324)
Signed-off-by: Ian Chen <[email protected]>
1 parent d2dff1a commit e03feb1

File tree

7 files changed

+54
-22
lines changed

7 files changed

+54
-22
lines changed

src/RenderingSensor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ RenderingSensor::RenderingSensor() :
4747
//////////////////////////////////////////////////
4848
RenderingSensor::~RenderingSensor()
4949
{
50-
if (!this->dataPtr->scene)
50+
if (!this->dataPtr->scene || !this->dataPtr->scene->IsInitialized())
5151
return;
5252
for (auto &s : this->dataPtr->sensors)
5353
{

test/integration/boundingbox_camera.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,11 @@ void BoundingBoxCameraSensorTest::BoxesWithBuiltinSDF(
344344

345345
g_mutex.unlock();
346346

347+
// Clean up rendering ptrs
348+
camera.reset();
349+
347350
// Clean up
351+
mgr.Remove(sensor->Id());
348352
engine->DestroyScene(scene);
349353
rendering::unloadEngine(engine->Name());
350354
}
@@ -465,7 +469,11 @@ void BoundingBoxCameraSensorTest::Boxes3DWithBuiltinSDF(
465469

466470
g_mutex.unlock();
467471

472+
// Clean up rendering ptrs
473+
camera.reset();
474+
468475
// Clean up
476+
mgr.Remove(sensor->Id());
469477
engine->DestroyScene(scene);
470478
rendering::unloadEngine(engine->Name());
471479
}

test/integration/depth_camera.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
222222
box->SetLocalRotation(0, 0, 0);
223223
box->SetLocalScale(unitBoxSize, unitBoxSize, unitBoxSize);
224224
box->SetMaterial(blue);
225+
scene->DestroyMaterial(blue);
225226
root->AddChild(box);
226227

227228
// do the test
@@ -336,11 +337,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
336337
EXPECT_EQ(9, infoMsg.rectification_matrix().size());
337338

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

345344
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
346345
for (int sleep = 0;
@@ -372,11 +371,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
372371
g_mutex.unlock();
373372

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

381378
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
382379
for (int sleep = 0;
@@ -408,11 +405,9 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
408405

409406

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

417412
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
418413
for (int sleep = 0;
@@ -497,7 +492,12 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(
497492
g_mutex.unlock();
498493
g_pcMutex.unlock();
499494

495+
// clean up rendering ptrs
496+
blue.reset();
497+
box.reset();
498+
500499
// Clean up
500+
mgr.Remove(depthSensor->Id());
501501
engine->DestroyScene(scene);
502502
gz::rendering::unloadEngine(engine->Name());
503503
}

test/integration/gpu_lidar_sensor.cc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ void GpuLidarSensorTest::CreateGpuLidar(const std::string &_renderEngine)
278278

279279
// Clean up
280280
c.reset();
281+
mgr.Remove(sensor->Id());
281282
engine->DestroyScene(scene);
282283
gz::rendering::unloadEngine(engine->Name());
283284
}
@@ -416,8 +417,11 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine)
416417
EXPECT_FALSE(pointMsgs.back().is_dense());
417418
EXPECT_EQ(32u * horzSamples * vertSamples, pointMsgs.back().data().size());
418419

420+
// Clean up rendering ptrs
421+
visualBox1.reset();
422+
419423
// Clean up
420-
//
424+
mgr.Remove(sensor->Id());
421425
engine->DestroyScene(scene);
422426
gz::rendering::unloadEngine(engine->Name());
423427
}
@@ -573,7 +577,14 @@ void GpuLidarSensorTest::TestThreeBoxes(const std::string &_renderEngine)
573577
for (unsigned int i = 0; i < sensor1->RayCount(); ++i)
574578
EXPECT_DOUBLE_EQ(sensor2->Range(i), gz::math::INF_D);
575579

580+
// Clean up rendering ptrs
581+
visualBox1.reset();
582+
visualBox2.reset();
583+
visualBox3.reset();
584+
576585
// Clean up
586+
mgr.Remove(sensor1->Id());
587+
mgr.Remove(sensor2->Id());
577588
engine->DestroyScene(scene);
578589
gz::rendering::unloadEngine(engine->Name());
579590
}
@@ -693,7 +704,11 @@ void GpuLidarSensorTest::VerticalLidar(const std::string &_renderEngine)
693704
}
694705
}
695706

707+
// Clean up rendering ptrs
708+
visualBox1.reset();
709+
696710
// Clean up
711+
mgr.Remove(sensor->Id());
697712
engine->DestroyScene(scene);
698713
gz::rendering::unloadEngine(engine->Name());
699714
}
@@ -819,8 +834,12 @@ void GpuLidarSensorTest::ManualUpdate(const std::string &_renderEngine)
819834
EXPECT_DOUBLE_EQ(sensor2->Range(last), gz::math::INF_D);
820835
#endif
821836

837+
// Clean up rendering ptrs
838+
visualBox1.reset();
839+
822840
// Clean up
823-
//
841+
mgr.Remove(sensor1->Id());
842+
mgr.Remove(sensor2->Id());
824843
engine->DestroyScene(scene);
825844
gz::rendering::unloadEngine(engine->Name());
826845
}
@@ -859,7 +878,6 @@ void GpuLidarSensorTest::Topic(const std::string &_renderEngine)
859878
// Create a GpuLidarSensor
860879
gz::sensors::Manager mgr;
861880

862-
863881
// Default topic
864882
{
865883
const std::string topic;

test/integration/rgbd_camera.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
242242
box->SetLocalRotation(0, 0, 0);
243243
box->SetLocalScale(unitBoxSize, unitBoxSize, unitBoxSize);
244244
box->SetMaterial(blue);
245+
scene->DestroyMaterial(blue);
245246
root->AddChild(box);
246247

247248
// do the test
@@ -529,11 +530,9 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
529530
g_imgMutex.unlock();
530531

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

538537
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
539538
for (int sleep = 0; sleep < 300 &&
@@ -635,11 +634,9 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
635634
g_pcMutex.unlock();
636635

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

644641
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
645642
for (int sleep = 0; sleep < 300 &&
@@ -740,7 +737,12 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(
740737
g_imgMutex.unlock();
741738
g_pcMutex.unlock();
742739

740+
// Clean up rendering ptrs
741+
box.reset();
742+
blue.reset();
743+
743744
// Clean up
745+
mgr.Remove(rgbdSensor->Id());
744746
engine->DestroyScene(scene);
745747
rendering::unloadEngine(engine->Name());
746748
}

test/integration/segmentation_camera.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ void SegmentationCameraSensorTest::ImagesWithBuiltinSDF(
352352
}
353353
}
354354

355+
// Clean up rendering ptrs
356+
camera.reset();
357+
355358
// Clean up
359+
mgr.Remove(sensor->Id());
356360
engine->DestroyScene(scene);
357361
ignition::rendering::unloadEngine(engine->Name());
358362
}

test/integration/thermal_camera.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,9 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
282282
EXPECT_EQ(9, infoMsg.rectification_matrix().size());
283283

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

291289
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
292290
for (int sleep = 0;
@@ -316,11 +314,9 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
316314
g_mutex.unlock();
317315

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

325321
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
326322
for (int sleep = 0;
@@ -352,7 +348,11 @@ void ThermalCameraSensorTest::ImagesWithBuiltinSDF(
352348
delete [] g_thermalBuffer;
353349
g_thermalBuffer = nullptr;
354350

351+
// Clean up rendering ptrs
352+
box.reset();
353+
355354
// Clean up
355+
mgr.Remove(thermalSensor->Id());
356356
engine->DestroyScene(scene);
357357
gz::rendering::unloadEngine(engine->Name());
358358
}
@@ -543,11 +543,9 @@ void ThermalCameraSensorTest::Images8BitWithBuiltinSDF(
543543
EXPECT_EQ(9, infoMsg.rectification_matrix().size());
544544

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

552550
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
553551
for (int sleep = 0;
@@ -578,11 +576,9 @@ void ThermalCameraSensorTest::Images8BitWithBuiltinSDF(
578576
g_mutex.unlock();
579577

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

587583
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
588584
for (int sleep = 0;
@@ -614,7 +610,11 @@ void ThermalCameraSensorTest::Images8BitWithBuiltinSDF(
614610
delete [] g_thermalBuffer8Bit;
615611
g_thermalBuffer8Bit = nullptr;
616612

613+
// Clean up rendering ptrs
614+
box.reset();
615+
617616
// Clean up
617+
mgr.Remove(thermalSensor->Id());
618618
engine->DestroyScene(scene);
619619
gz::rendering::unloadEngine(engine->Name());
620620
}

0 commit comments

Comments
 (0)