Fix deadlock in GPUDevice caused by f2c594569d

This commit is contained in:
Wojtek Figat
2022-12-12 20:16:03 +01:00
parent 516e3fbc65
commit 48b88af88a
2 changed files with 13 additions and 10 deletions

View File

@@ -374,24 +374,24 @@ bool GPUDevice::CanDraw()
void GPUDevice::AddResource(GPUResource* resource)
{
Locker.Lock();
_resourcesLock.Lock();
ASSERT(resource && !_resources.Contains(resource));
_resources.Add(resource);
Locker.Unlock();
_resourcesLock.Unlock();
}
void GPUDevice::RemoveResource(GPUResource* resource)
{
Locker.Lock();
_resourcesLock.Lock();
ASSERT(resource && _resources.Contains(resource));
_resources.Remove(resource);
Locker.Unlock();
_resourcesLock.Unlock();
}
void GPUDevice::DumpResourcesToLog() const
{
StringBuilder output;
Locker.Lock();
_resourcesLock.Lock();
output.AppendFormat(TEXT("GPU Resources dump. Count: {0}, total GPU memory used: {1}"), _resources.Count(), Utilities::BytesToText(GetMemoryUsage()));
output.AppendLine();
@@ -428,7 +428,7 @@ void GPUDevice::DumpResourcesToLog() const
output.AppendLine();
}
Locker.Unlock();
_resourcesLock.Unlock();
LOG_STR(Info, output.ToStringView());
}
@@ -449,11 +449,13 @@ void GPUDevice::preDispose()
// Release GPU resources memory and unlink from device
// Note: after that no GPU resources should be used/created, only deleted
_resourcesLock.Lock();
for (int32 i = _resources.Count() - 1; i >= 0 && i < _resources.Count(); i--)
{
_resources[i]->OnDeviceDispose();
}
_resources.Clear();
_resourcesLock.Unlock();
Locker.Unlock();
}
@@ -592,18 +594,18 @@ void GPUDevice::Dispose()
uint64 GPUDevice::GetMemoryUsage() const
{
uint64 result = 0;
Locker.Lock();
_resourcesLock.Lock();
for (int32 i = 0; i < _resources.Count(); i++)
result += _resources[i]->GetMemoryUsage();
Locker.Unlock();
_resourcesLock.Unlock();
return result;
}
Array<GPUResource*> GPUDevice::GetResources() const
{
Locker.Lock();
_resourcesLock.Lock();
Array<GPUResource*> result = _resources;
Locker.Unlock();
_resourcesLock.Unlock();
return result;
}

View File

@@ -94,6 +94,7 @@ protected:
struct PrivateData;
PrivateData* _res;
Array<GPUResource*> _resources;
CriticalSection _resourcesLock;
protected:
/// <summary>