Calling GraphicsStateCollection.GetVariants on a GraphicsStateCollection that was used to trace is causing the engine to crash. I’m using Unity 6000.0.23 and URP. It crashes in the editor and windows builds.
I have submitted bug-report IN-87175 with several crash dumps for you to inspect.
Here is the code snippet that causes the crash, the way how I implemented it follows the advice given by Unity staff here:
// Start trace when level starts
m_GraphicsStateCollection = new GraphicsStateCollection();
m_GraphicsStateCollection.BeginTrace();
// Playing game...
// End trace when level ended and proceeds to next scene
m_GraphicsStateCollection.EndTrace();
var variants = new List<GraphicsStateCollection.ShaderVariant>();
m_GraphicsStateCollection.GetVariants(variants); // This line crashes
The reason why I call GetVariants is that I want to merge it with existing graphics state collections, so that I can feed it new data incrementally with each play.
The error message:
The relevant editor stack trace:
(KERNELBASE) RaiseException
(Unity) LaunchBugReporter
(Unity) EditorMonoConsole::LogToConsoleImplementation
(Unity) EditorMonoConsole::LogToConsoleImplementation
(Unity) DebugStringToFilePostprocessedStacktrace
(Unity) DebugStringToFile
(Unity) MemoryManager::Allocate
(Unity) malloc_internal
(Unity) core::StringStorageDefault<char>::grow
(Unity) GraphicsStateCollection::KeywordsFromShaderAndKeywordNames
(Unity) GraphicsStateCollection::GetVariants
(Unity) GraphicsStateCollection_CUSTOM_GetVariants
(Mono JIT Code) (wrapper managed-to-native) UnityEngine.Experimental.Rendering.GraphicsStateCollection:GetVariants_Injected (intptr,UnityEngine.Experimental.Rendering.GraphicsStateCollection/ShaderVariant[])
(Mono JIT Code) UnityEngine.Experimental.Rendering.GraphicsStateCollection:GetVariants (UnityEngine.Experimental.Rendering.GraphicsStateCollection/ShaderVariant[])
(Mono JIT Code) UnityEngine.Experimental.Rendering.GraphicsStateCollection:GetVariants (System.Collections.Generic.List`1<UnityEngine.Experimental.Rendering.GraphicsStateCollection/ShaderVariant>)
The relevant build stacktrace:
(UnityPlayer) GraphicsStateCollection::KeywordsFromShaderAndKeywordNames
(UnityPlayer) GraphicsStateCollection::GetVariants
(UnityPlayer) GraphicsStateCollection_CUSTOM_GetVariants
Is this a bug or is the way how I use it incorrect?
EDIT: I also just realized I can’t merge GraphicsStateCollection’s because there is no API to check if a GraphicsState is added to a Variant already. I guess I have to come up with something that doesn’t require a merge…
