Skip to content

Commit

Permalink
Document possible nested calls to notifyResourceDestroyed/Created ins…
Browse files Browse the repository at this point in the history
…ide notifyDeviceLost/Restored, minor code cleanup
  • Loading branch information
eugenegff committed Dec 7, 2024
1 parent 498e0f9 commit 2485286
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
33 changes: 12 additions & 21 deletions RenderSystems/Direct3D11/src/OgreD3D11DeviceResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Ogre
}

// ------------------------------------------------------------------------
static D3D11DeviceResourceManager *gs_D3D11DeviceResourceManager = NULL;
static D3D11DeviceResourceManager *gs_D3D11DeviceResourceManager = nullptr;

D3D11DeviceResourceManager *D3D11DeviceResourceManager::get()
{
Expand All @@ -51,15 +51,15 @@ namespace Ogre

D3D11DeviceResourceManager::D3D11DeviceResourceManager()
{
assert( gs_D3D11DeviceResourceManager == NULL );
assert( gs_D3D11DeviceResourceManager == nullptr );
gs_D3D11DeviceResourceManager = this;
}

D3D11DeviceResourceManager::~D3D11DeviceResourceManager()
{
assert( mResources.empty() );
assert( gs_D3D11DeviceResourceManager == this );
gs_D3D11DeviceResourceManager = NULL;
gs_D3D11DeviceResourceManager = nullptr;
}

void D3D11DeviceResourceManager::notifyResourceCreated( D3D11DeviceResource *deviceResource )
Expand All @@ -86,32 +86,23 @@ namespace Ogre
assert( mResourcesCopy.empty() ); // reentrancy is not expected nor supported
mResourcesCopy = mResources;

vector<D3D11DeviceResource *>::type::iterator it = mResourcesCopy.begin();
vector<D3D11DeviceResource *>::type::iterator en = mResourcesCopy.end();
while( it != en )
{
if( D3D11DeviceResource *deviceResource = *it )
deviceResource->notifyDeviceLost( device );
++it;
}
for( D3D11DeviceResource *deviceResource : mResourcesCopy )
if( deviceResource != nullptr )
deviceResource->notifyDeviceLost( device ); // notifyResourceDestroyed() can be called

mResourcesCopy.clear();
}

void D3D11DeviceResourceManager::notifyDeviceRestored( D3D11Device *device )
{
assert( mResourcesCopy.empty() ); // reentrancy is not expected nor supported
mResourcesCopy = mResources;

for( unsigned pass = 0; pass < 2; ++pass )
{
vector<D3D11DeviceResource *>::type::iterator it = mResourcesCopy.begin();
vector<D3D11DeviceResource *>::type::iterator en = mResourcesCopy.end();
while( it != en )
{
if( D3D11DeviceResource *deviceResource = *it )
deviceResource->notifyDeviceRestored( device, pass );
++it;
}
}
for( D3D11DeviceResource *deviceResource : mResourcesCopy )
if( deviceResource != nullptr )
deviceResource->notifyDeviceRestored( device, pass ); // subresources created

mResourcesCopy.clear();
}

Expand Down
33 changes: 12 additions & 21 deletions RenderSystems/Vulkan/src/OgreVulkanDeviceResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Ogre
}

// ------------------------------------------------------------------------
static VulkanDeviceResourceManager *gs_VulkanDeviceResourceManager = NULL;
static VulkanDeviceResourceManager *gs_VulkanDeviceResourceManager = nullptr;

VulkanDeviceResourceManager *VulkanDeviceResourceManager::get()
{
Expand All @@ -51,15 +51,15 @@ namespace Ogre

VulkanDeviceResourceManager::VulkanDeviceResourceManager()
{
assert( gs_VulkanDeviceResourceManager == NULL );
assert( gs_VulkanDeviceResourceManager == nullptr );
gs_VulkanDeviceResourceManager = this;
}

VulkanDeviceResourceManager::~VulkanDeviceResourceManager()
{
assert( mResources.empty() );
assert( gs_VulkanDeviceResourceManager == this );
gs_VulkanDeviceResourceManager = NULL;
gs_VulkanDeviceResourceManager = nullptr;
}

void VulkanDeviceResourceManager::notifyResourceCreated( VulkanDeviceResource *deviceResource )
Expand Down Expand Up @@ -92,14 +92,10 @@ namespace Ogre
assert( mResourcesCopy.empty() ); // reentrancy is not expected nor supported
mResourcesCopy = mResources;

vector<VulkanDeviceResource *>::type::iterator it = mResourcesCopy.begin();
vector<VulkanDeviceResource *>::type::iterator en = mResourcesCopy.end();
while( it != en )
{
if( VulkanDeviceResource *deviceResource = *it )
deviceResource->notifyDeviceLost();
++it;
}
for( VulkanDeviceResource *deviceResource : mResourcesCopy )
if( deviceResource != nullptr )
deviceResource->notifyDeviceLost(); // notifyResourceDestroyed() can be called inside

mResourcesCopy.clear();
}

Expand All @@ -109,17 +105,12 @@ namespace Ogre

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

for( unsigned pass = 0; pass < 2; ++pass )
{
vector<VulkanDeviceResource *>::type::iterator it = mResourcesCopy.begin();
vector<VulkanDeviceResource *>::type::iterator en = mResourcesCopy.end();
while( it != en )
{
if( VulkanDeviceResource *deviceResource = *it )
deviceResource->notifyDeviceRestored( pass );
++it;
}
}
for( VulkanDeviceResource *deviceResource : mResourcesCopy )
if( deviceResource != nullptr )
deviceResource->notifyDeviceRestored( pass ); // subresources could be created

mResourcesCopy.clear();
}

Expand Down

0 comments on commit 2485286

Please sign in to comment.