Slate.ResourceManager.LockResourceDuringGC
Slate.ResourceManager.LockResourceDuringGC
#Overview
name: Slate.ResourceManager.LockResourceDuringGC
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Lock the Slate RHI Resource Manager when GCing and when the loading screen has ownership to prevent multithreaded access to the resources.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of Slate.ResourceManager.LockResourceDuringGC is to control whether the Slate RHI Resource Manager should be locked during garbage collection (GC) and when the loading screen has ownership. This is done to prevent multithreaded access to the resources, which could lead to race conditions or other concurrency issues.
This setting variable is primarily used in the Slate RHI Renderer subsystem of Unreal Engine 5. It’s specifically utilized in the SlateRHIResourceManager class, which is responsible for managing RHI (Rendering Hardware Interface) resources for the Slate UI system.
The value of this variable is set through a console variable (CVar) named CVarSlateRHIResourceManagerLockWhenGCing. It’s defined as a static TAutoConsoleVariable
The associated variable CVarSlateRHIResourceManagerLockWhenGCing directly interacts with this setting. It’s used to retrieve the current value of the setting when needed, particularly in the OnPreGarbageCollect function of the FSlateRHIResourceManager class.
Developers must be aware that this variable affects the behavior of the Slate RHI Resource Manager during garbage collection. When set to true (which is the default), it will cause the ResourceCriticalSection to be locked during GC if a Slate loading thread is active. This can potentially impact performance but provides thread safety.
Best practices when using this variable include:
- Generally, leave it at its default value (true) unless you have a specific reason to change it.
- If you decide to change it, thoroughly test your application’s performance and stability, especially in multi-threaded scenarios.
- Be cautious when disabling this lock, as it could lead to race conditions if resources are accessed from multiple threads during garbage collection.
- Monitor your application’s performance during garbage collection, especially if you’ve modified this setting.
Regarding the associated variable CVarSlateRHIResourceManagerLockWhenGCing:
Its purpose is to provide a runtime-configurable way to control the Slate.ResourceManager.LockResourceDuringGC setting. It’s defined as a console variable, which means it can be changed at runtime through console commands.
This variable is used in the SlateRHIRenderer module, specifically in the FSlateRHIResourceManager class.
The value of this variable is set when it’s defined, with a default of true. However, being a console variable, its value can be changed at runtime.
It directly interacts with the Slate.ResourceManager.LockResourceDuringGC setting, effectively controlling its behavior.
Developers should be aware that changes to this variable will immediately affect the behavior of the Slate RHI Resource Manager during garbage collection. They should also note that the variable’s value is retrieved on the game thread (using GetValueOnGameThread()).
Best practices for using this variable include:
- Use it for debugging or performance tuning purposes.
- Be cautious when changing its value in a shipping build, as it could affect stability.
- If you need to change it frequently, consider exposing it in a config file or user settings menu rather than relying on console commands.
- Document any non-default usage of this variable in your project to ensure all team members are aware of its state.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIResourceManager.cpp:37
Scope: file
Source code excerpt:
static TAutoConsoleVariable<bool> CVarSlateRHIResourceManagerLockWhenGCing(
TEXT("Slate.ResourceManager.LockResourceDuringGC"),
true,
TEXT("Lock the Slate RHI Resource Manager when GCing and when the loading screen has ownership to prevent multithreaded access to the resources."));
class FSlateRHITextureAtlasFactory : public ISlateTextureAtlasFactory
{
public:
#Associated Variable and Callsites
This variable is associated with another variable named CVarSlateRHIResourceManagerLockWhenGCing
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIResourceManager.cpp:36
Scope: file
Source code excerpt:
DECLARE_CYCLE_STAT(TEXT("GetResource Time"), STAT_SlateGetResourceTime, STATGROUP_Slate);
static TAutoConsoleVariable<bool> CVarSlateRHIResourceManagerLockWhenGCing(
TEXT("Slate.ResourceManager.LockResourceDuringGC"),
true,
TEXT("Lock the Slate RHI Resource Manager when GCing and when the loading screen has ownership to prevent multithreaded access to the resources."));
class FSlateRHITextureAtlasFactory : public ISlateTextureAtlasFactory
{
#Loc: <Workspace>/Engine/Source/Runtime/SlateRHIRenderer/Private/SlateRHIResourceManager.cpp:306
Scope (from outer to inner):
file
function void FSlateRHIResourceManager::OnPreGarbageCollect
Source code excerpt:
{
check(bResourceCriticalSectionLockedForGC == false);
bResourceCriticalSectionLockedForGC = (GSlateLoadingThreadId != 0) && CVarSlateRHIResourceManagerLockWhenGCing.GetValueOnGameThread();
if (bResourceCriticalSectionLockedForGC)
{
ResourceCriticalSection.Lock();
}
}