diff --git a/ogre/include/ignition/rendering/ogre/OgreIncludes.hh b/ogre/include/ignition/rendering/ogre/OgreIncludes.hh index d858b8204..817bff8d4 100644 --- a/ogre/include/ignition/rendering/ogre/OgreIncludes.hh +++ b/ogre/include/ignition/rendering/ogre/OgreIncludes.hh @@ -22,6 +22,8 @@ #pragma GCC system_header #else #pragma warning(push, 0) + #pragma warning(disable:4275) + #pragma warning(disable:4005) #endif // This prevents some deprecation #warning messages on OSX 10.9 diff --git a/ogre/src/OgreRenderTarget.cc b/ogre/src/OgreRenderTarget.cc index 217c28a03..20b271e0a 100644 --- a/ogre/src/OgreRenderTarget.cc +++ b/ogre/src/OgreRenderTarget.cc @@ -20,6 +20,8 @@ # pragma GCC diagnostic ignored "-Wunused-parameter" #else # pragma warning(push, 0) +# pragma warning(disable: 4005) +# pragma warning(disable: 4275) #endif // leave this out of OgreIncludes as it conflicts with other files requiring // gl.h diff --git a/ogre2/src/Ogre2GpuRays.cc b/ogre2/src/Ogre2GpuRays.cc index b4bae0233..846cc33d3 100644 --- a/ogre2/src/Ogre2GpuRays.cc +++ b/ogre2/src/Ogre2GpuRays.cc @@ -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; @@ -278,7 +282,7 @@ void Ogre2LaserRetroMaterialSwitcher::cameraPreRenderScene( { try { - retroValue = std::get(tempLaserRetro); + retroValue = static_cast(std::get(tempLaserRetro)); } catch(std::bad_variant_access &e) { @@ -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; @@ -386,6 +390,9 @@ void Ogre2GpuRays::Init() ////////////////////////////////////////////////// void Ogre2GpuRays::Destroy() { + if (!this->dataPtr->ogreCamera) + return; + if (this->dataPtr->gpuRaysBuffer) { delete [] this->dataPtr->gpuRaysBuffer; @@ -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; + } + } } ///////////////////////////////////////////////// @@ -587,19 +621,19 @@ math::Vector2d Ogre2GpuRays::SampleCubemap(const math::Vector3d &_v, math::Vector2d uv; if (vAbs.Z() >= vAbs.X() && vAbs.Z() >= vAbs.Y()) { - _faceIndex = _v.Z() < 0.0 ? 5.0 : 4.0; + _faceIndex = _v.Z() < 0 ? 5 : 4; ma = 0.5 / vAbs.Z(); uv = math::Vector2d(_v.Z() < 0.0 ? -_v.X() : _v.X(), -_v.Y()); } else if (vAbs.Y() >= vAbs.X()) { - _faceIndex = _v.Y() < 0.0 ? 3.0 : 2.0; + _faceIndex = _v.Y() < 0 ? 3 : 2; ma = 0.5 / vAbs.Y(); uv = math::Vector2d(_v.X(), _v.Y() < 0.0 ? -_v.Z() : _v.Z()); } else { - _faceIndex = _v.X() < 0.0 ? 1.0 : 0.0; + _faceIndex = _v.X() < 0 ? 1 : 0; ma = 0.5 / vAbs.X(); uv = math::Vector2d(_v.X() < 0.0 ? _v.Z() : -_v.Z(), -_v.Y()); } @@ -689,7 +723,7 @@ void Ogre2GpuRays::CreateSampleTexture() // v pDest[index++] = uv.Y(); // face - pDest[index++] = faceIdx; + pDest[index++] = static_cast(faceIdx); // unused pDest[index++] = 1.0; h += hStep; diff --git a/ogre2/src/Ogre2RenderEngine.cc b/ogre2/src/Ogre2RenderEngine.cc index c3d18c929..29083d8f0 100644 --- a/ogre2/src/Ogre2RenderEngine.cc +++ b/ogre2/src/Ogre2RenderEngine.cc @@ -159,7 +159,7 @@ void Ogre2RenderEngine::Destroy() delete this->ogreLogManager; this->ogreLogManager = nullptr; -#if not (__APPLE__ || _WIN32) +#if !defined(__APPLE__) && !defined(_WIN32) if (this->dummyDisplay) { Display *x11Display = static_cast(this->dummyDisplay); @@ -382,7 +382,7 @@ void Ogre2RenderEngine::CreateLogger() ////////////////////////////////////////////////// void Ogre2RenderEngine::CreateContext() { -#if not (__APPLE__ || _WIN32) +#if !defined(__APPLE__) && !defined(_WIN32) if (this->Headless()) { // Nothing to do diff --git a/ogre2/src/Ogre2RenderTarget.cc b/ogre2/src/Ogre2RenderTarget.cc index b7caed451..98030b9fa 100644 --- a/ogre2/src/Ogre2RenderTarget.cc +++ b/ogre2/src/Ogre2RenderTarget.cc @@ -852,12 +852,16 @@ void Ogre2RenderTarget::RebuildMaterial() ////////////////////////////////////////////////// // Ogre2RenderTexture ////////////////////////////////////////////////// +#ifndef _WIN32 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif Ogre2RenderTexture::Ogre2RenderTexture() { } +#ifndef _WIN32 #pragma GCC diagnostic pop +#endif ////////////////////////////////////////////////// Ogre2RenderTexture::~Ogre2RenderTexture() diff --git a/ogre2/src/Ogre2Scene.cc b/ogre2/src/Ogre2Scene.cc index 5f9837fd1..d0804974a 100644 --- a/ogre2/src/Ogre2Scene.cc +++ b/ogre2/src/Ogre2Scene.cc @@ -651,7 +651,7 @@ void Ogre2Scene::UpdateShadowNode() // directional lights unsigned int atlasId = 0u; unsigned int texSize = 2048u; - unsigned int halfTexSize = texSize * 0.5; + unsigned int halfTexSize = static_cast(texSize * 0.5); for (unsigned int i = 0; i < dirLightCount; ++i) { shadowParam.technique = Ogre::SHADOWMAP_PSSM; @@ -866,12 +866,16 @@ void Ogre2Scene::CreateShadowNodeWithSettings( for (size_t j = 0; j < numSplits; ++j) { Ogre::Vector2 uvOffset( - shadowParam.atlasStart[j].x, shadowParam.atlasStart[j].y); + static_cast(shadowParam.atlasStart[j].x), + static_cast(shadowParam.atlasStart[j].y)); Ogre::Vector2 uvLength( - shadowParam.resolution[j].x, shadowParam.resolution[j].y); + static_cast(shadowParam.resolution[j].x), + static_cast(shadowParam.resolution[j].y)); - uvOffset /= Ogre::Vector2(texResolution.x, texResolution.y); - uvLength /= Ogre::Vector2(texResolution.x, texResolution.y); + uvOffset /= Ogre::Vector2(static_cast(texResolution.x), + static_cast(texResolution.y)); + uvLength /= Ogre::Vector2(static_cast(texResolution.x), + static_cast(texResolution.y)); const Ogre::String texName = "atlas" + Ogre::StringConverter::toString(shadowParam.atlasId); diff --git a/ogre2/src/Ogre2SegmentationMaterialSwitcher.cc b/ogre2/src/Ogre2SegmentationMaterialSwitcher.cc index 133a07e6a..923eaaf28 100644 --- a/ogre2/src/Ogre2SegmentationMaterialSwitcher.cc +++ b/ogre2/src/Ogre2SegmentationMaterialSwitcher.cc @@ -87,8 +87,8 @@ bool Ogre2SegmentationMaterialSwitcher::IsTakenColor(const math::Color &_color) { // Get the int value of the 24 bit color // Multiply by 255 as color values are normalized - int64_t colorId = (_color.R() * 255) * 256 * 256 + - (_color.G() * 255) * 256 + (_color.B() * 255); + int64_t colorId = static_cast((_color.R() * 255) * 256 * 256 + + (_color.G() * 255) * 256 + (_color.B() * 255)); if (this->takenColors.count(colorId)) { @@ -117,7 +117,10 @@ math::Color Ogre2SegmentationMaterialSwitcher::LabelToColor(int64_t _label, int g = distribution(this->generator); int b = distribution(this->generator); - math::Color color(r, g, b); + math::Color color( + static_cast(r), + static_cast(g), + static_cast(b)); // if the label is colored before return the color // don't check for taken colors in that case, all items diff --git a/ogre2/src/Ogre2ThermalCamera.cc b/ogre2/src/Ogre2ThermalCamera.cc index c7aac0b2d..5cb5a2d50 100644 --- a/ogre2/src/Ogre2ThermalCamera.cc +++ b/ogre2/src/Ogre2ThermalCamera.cc @@ -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; @@ -288,7 +288,7 @@ void Ogre2ThermalCameraMaterialSwitcher::cameraPreRenderScene( { try { - temp = std::get(tempAny); + temp = static_cast(std::get(tempAny)); } catch(std::bad_variant_access &e) { @@ -536,6 +536,7 @@ void Ogre2ThermalCamera::Destroy() { Ogre::MaterialManager::getSingleton().remove( this->dataPtr->thermalMaterial->getName()); + this->dataPtr->thermalMaterial.setNull(); } if (!this->dataPtr->ogreCompositorWorkspaceDef.empty()) @@ -560,6 +561,8 @@ void Ogre2ThermalCamera::Destroy() this->ogreCamera = nullptr; } } + + this->dataPtr->thermalMaterialSwitcher.reset(); } ////////////////////////////////////////////////// diff --git a/src/base/BaseScene.cc b/src/base/BaseScene.cc index f56e7928c..8d1011138 100644 --- a/src/base/BaseScene.cc +++ b/src/base/BaseScene.cc @@ -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; } diff --git a/test/integration/camera.cc b/test/integration/camera.cc index e83b1e6cb..426094a22 100644 --- a/test/integration/camera.cc +++ b/test/integration/camera.cc @@ -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()); }