Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy root node and clean up sensor resources on exit #617

Merged
merged 3 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion ogre2/src/Ogre2GpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ class ignition::rendering::Ogre2GpuRaysPrivate

/// \brief Min allowed angle in radians;
public: const math::Angle kMinAllowedAngle = 1e-4;

/// \brief Max number of cameras used for creating the cubemap of depth
/// textures for generating lidar data
public: const unsigned int kCubeCameraCount = 6;
};

using namespace ignition;
Expand Down Expand Up @@ -357,7 +361,7 @@ Ogre2GpuRays::Ogre2GpuRays()
// r = depth, g = retro, and b = n/a
this->channels = 3u;

for (unsigned int i = 0; i < 6u; ++i)
for (unsigned int i = 0; i < this->dataPtr->kCubeCameraCount; ++i)
{
this->dataPtr->cubeCam[i] = nullptr;
this->dataPtr->ogreCompositorWorkspace1st[i] = nullptr;
Expand Down Expand Up @@ -386,6 +390,9 @@ void Ogre2GpuRays::Init()
//////////////////////////////////////////////////
void Ogre2GpuRays::Destroy()
{
if (!this->dataPtr->ogreCamera)
return;

if (this->dataPtr->gpuRaysBuffer)
{
delete [] this->dataPtr->gpuRaysBuffer;
Expand Down Expand Up @@ -465,6 +472,33 @@ void Ogre2GpuRays::Destroy()
this->dataPtr->ogreCompositorNodeDef2nd);
this->dataPtr->ogreCompositorWorkspaceDef2nd.clear();
}

if (this->scene)
{
Ogre::SceneManager *ogreSceneManager = this->scene->OgreSceneManager();
if (ogreSceneManager == nullptr)
{
ignerr << "Scene manager not available. "
<< "Unable to remove cameras and listeners" << std::endl;
}
else
{
for (unsigned int i = 0u; i < this->dataPtr->kCubeCameraCount; ++i)
{
if (this->dataPtr->cubeCam[i])
{
this->dataPtr->cubeCam[i]->removeListener(
this->dataPtr->particleNoiseListener[i].get());
ogreSceneManager->destroyCamera(this->dataPtr->cubeCam[i]);
this->dataPtr->cubeCam[i] = nullptr;
}
this->dataPtr->particleNoiseListener[i].reset();
this->dataPtr->laserRetroMaterialSwitcher[i].reset();
}
ogreSceneManager->destroyCamera(this->dataPtr->ogreCamera);
this->dataPtr->ogreCamera = nullptr;
}
}
}

/////////////////////////////////////////////////
Expand Down
5 changes: 4 additions & 1 deletion ogre2/src/Ogre2ThermalCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class ignition::rendering::Ogre2ThermalCameraPrivate
public: Ogre::CompositorWorkspace *ogreCompositorWorkspace;

/// \brief Thermal textures.
public: Ogre::TextureGpu *ogreThermalTexture;
public: Ogre::TextureGpu *ogreThermalTexture{nullptr};

/// \brief Dummy render texture for the thermal data
public: RenderTexturePtr thermalTexture = nullptr;
Expand Down Expand Up @@ -536,6 +536,7 @@ void Ogre2ThermalCamera::Destroy()
{
Ogre::MaterialManager::getSingleton().remove(
this->dataPtr->thermalMaterial->getName());
this->dataPtr->thermalMaterial.setNull();
}

if (!this->dataPtr->ogreCompositorWorkspaceDef.empty())
Expand All @@ -560,6 +561,8 @@ void Ogre2ThermalCamera::Destroy()
this->ogreCamera = nullptr;
}
}

this->dataPtr->thermalMaterialSwitcher.reset();
}

//////////////////////////////////////////////////
Expand Down
8 changes: 7 additions & 1 deletion src/base/BaseScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,13 @@ bool BaseScene::LegacyAutoGpuFlush() const
//////////////////////////////////////////////////
void BaseScene::Clear()
{
this->nodes->DestroyAll();
this->DestroyNodes();
auto root = this->RootVisual();
if (root)
{
root->RemoveChildren();
this->DestroyNode(root);
}
this->DestroyMaterials();
this->nextObjectId = ignition::math::MAX_UI16;
}
Expand Down
9 changes: 9 additions & 0 deletions test/integration/camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,15 @@ void CameraTest::ShaderSelection(const std::string &_renderEngine)

// Clean up
engine->DestroyScene(scene);

ASSERT_EQ(1u, camera.use_count());
ASSERT_EQ(1u, gpuRays.use_count());
ASSERT_EQ(1u, thermalCamera.use_count());
if (segmentationCamera)
{
ASSERT_EQ(1u, segmentationCamera.use_count());
}

rendering::unloadEngine(engine->Name());
}

Expand Down