Skip to content

Commit

Permalink
[Vk] VulkanDeviceResource derived classes are sometimes created on ot…
Browse files Browse the repository at this point in the history
…her threads, so registration should be protected by mutex, recursive as notifyResourceDestroyed() can happen inside notifyDeviceLost()
  • Loading branch information
eugenegff committed Dec 6, 2024
1 parent 1dc278a commit e0846af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RenderSystems/Vulkan/include/OgreVulkanDeviceResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ THE SOFTWARE.

#include "OgreVulkanPrerequisites.h"

#include <mutex>
#include "ogrestd/vector.h"

namespace Ogre
Expand Down Expand Up @@ -73,6 +74,7 @@ namespace Ogre
~VulkanDeviceResourceManager(); // protected and non-virtual

private:
std::recursive_mutex mResourcesMutex;
vector<VulkanDeviceResource *>::type mResources, mResourcesCopy;
};

Expand Down
8 changes: 8 additions & 0 deletions RenderSystems/Vulkan/src/OgreVulkanDeviceResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ namespace Ogre

void VulkanDeviceResourceManager::notifyResourceCreated( VulkanDeviceResource *deviceResource )
{
std::lock_guard<std::recursive_mutex> guard(mResourcesMutex);

assert( std::find( mResources.begin(), mResources.end(), deviceResource ) == mResources.end() );
mResources.push_back( deviceResource );
}

void VulkanDeviceResourceManager::notifyResourceDestroyed( VulkanDeviceResource *deviceResource )
{
std::lock_guard<std::recursive_mutex> guard(mResourcesMutex);

vector<VulkanDeviceResource *>::type::iterator it =
std::find( mResources.begin(), mResources.end(), deviceResource );
assert( it != mResources.end() );
Expand All @@ -83,6 +87,8 @@ namespace Ogre

void VulkanDeviceResourceManager::notifyDeviceLost()
{
std::lock_guard<std::recursive_mutex> guard(mResourcesMutex);

assert( mResourcesCopy.empty() ); // reentrancy is not expected nor supported
mResourcesCopy = mResources;

Expand All @@ -99,6 +105,8 @@ namespace Ogre

void VulkanDeviceResourceManager::notifyDeviceRestored()
{
std::lock_guard<std::recursive_mutex> guard(mResourcesMutex);

assert( mResourcesCopy.empty() ); // reentrancy is not expected nor supported
mResourcesCopy = mResources;
for( unsigned pass = 0; pass < 2; ++pass )
Expand Down

0 comments on commit e0846af

Please sign in to comment.