diff --git a/RenderSystems/Vulkan/include/OgreVulkanDeviceResource.h b/RenderSystems/Vulkan/include/OgreVulkanDeviceResource.h index 30516e3076..b88cbe594d 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanDeviceResource.h +++ b/RenderSystems/Vulkan/include/OgreVulkanDeviceResource.h @@ -30,6 +30,7 @@ THE SOFTWARE. #include "OgreVulkanPrerequisites.h" +#include #include "ogrestd/vector.h" namespace Ogre @@ -73,6 +74,7 @@ namespace Ogre ~VulkanDeviceResourceManager(); // protected and non-virtual private: + std::recursive_mutex mResourcesMutex; vector::type mResources, mResourcesCopy; }; diff --git a/RenderSystems/Vulkan/src/OgreVulkanDeviceResource.cpp b/RenderSystems/Vulkan/src/OgreVulkanDeviceResource.cpp index e986ac5849..2508f5953b 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanDeviceResource.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanDeviceResource.cpp @@ -64,12 +64,16 @@ namespace Ogre void VulkanDeviceResourceManager::notifyResourceCreated( VulkanDeviceResource *deviceResource ) { + std::lock_guard guard( mResourcesMutex ); + assert( std::find( mResources.begin(), mResources.end(), deviceResource ) == mResources.end() ); mResources.push_back( deviceResource ); } void VulkanDeviceResourceManager::notifyResourceDestroyed( VulkanDeviceResource *deviceResource ) { + std::lock_guard guard( mResourcesMutex ); + vector::type::iterator it = std::find( mResources.begin(), mResources.end(), deviceResource ); assert( it != mResources.end() ); @@ -83,6 +87,8 @@ namespace Ogre void VulkanDeviceResourceManager::notifyDeviceLost() { + std::lock_guard guard( mResourcesMutex ); + assert( mResourcesCopy.empty() ); // reentrancy is not expected nor supported mResourcesCopy = mResources; @@ -99,6 +105,8 @@ namespace Ogre void VulkanDeviceResourceManager::notifyDeviceRestored() { + std::lock_guard guard( mResourcesMutex ); + assert( mResourcesCopy.empty() ); // reentrancy is not expected nor supported mResourcesCopy = mResources; for( unsigned pass = 0; pass < 2; ++pass )