Fix for crash changing MaterialQualityLevel

This question was created in reference to: [Render code crashes caused by ShaderMap mismatch in [Content removed]

We are experiencing this same issue as the other developer, however we have found a fix. The issue is because in ScalabilityCVarsSinkCallback(), when it creates the FGlobalComponentRecreateRenderStateContext, the constructor of it calls UpdateAllPrimitiveSceneInfosForScenes(). This launches a task on RenderThread which calls FPrimitiveSceneInfo::CacheMeshDrawCommands. This can then overlap with the assignment of GCachedScalabilityCVars which causes the issue.

We were able to fix this by adding another FlushRenderingCommands() between creating the FGlobalComponentRecreateRenderStateContext and assigning GCachedScalabilityCVars here to wait for the UpdateAllPrimitiveSceneInfosForScenes RT work to finish.

We wanted to pass this along since it seemed from the other thread that Epic didn’t have a reliable repro for the issue.

Thanks!

Steps to Reproduce
Load into a map with many different materials using QualityLevel switch nodes and then change the MaterialQualityLevel via Scalability

Thanks for the fix! We’re taking a look and will likely implement something similar.

Hello again! Just wanted to drop this link here for tracking this issue Unreal Engine Issues and Bug Tracker (UE\-355606) which should be visible publicly soon.