diff --git a/ogre2/src/Ogre2RayQuery.cc b/ogre2/src/Ogre2RayQuery.cc index 180f7d916..abbff3cad 100644 --- a/ogre2/src/Ogre2RayQuery.cc +++ b/ogre2/src/Ogre2RayQuery.cc @@ -71,6 +71,16 @@ Ogre2RayQuery::Ogre2RayQuery() ////////////////////////////////////////////////// Ogre2RayQuery::~Ogre2RayQuery() { + if (this->dataPtr->rayQuery) + { + Ogre2ScenePtr ogreScene = + std::dynamic_pointer_cast(this->Scene()); + if (ogreScene) + { + ogreScene->OgreSceneManager()->destroyQuery(this->dataPtr->rayQuery); + this->dataPtr->rayQuery = nullptr; + } + } } //////////////////////////////////////////////////