UE 5.7.4 — Use-after-free of FD3D12SamplerState in FD3D12DescriptorCache::BuildSamplerTable during Nanite BasePass

Hi everyone, I found the solution to my problem. I had two different triggers causing the same crash: one was related to Nanite, and the other was caused by an invalid shader. Both were sharing information through a Material Parameter Collection.

Since I only have around five Material Parameter Collections in the entire project, I decided to keep them loaded at all time (Basically, what I did was create an array of hard references to the five Material Parameter Collections in the Game Instance. So hopefully the solution I found can help others too, because I can see that a lot of people are having this problem.). One of the things happening in both cases was that they were trying to be used after they had already been released.

So I kept them permanently loaded, and that fixed the bug. I’ve had the game running for a full day now, and it hasn’t crashed or thrown any errors.

Lastly, one of the things I fixed that wasn’t directly causing the crash, but could have triggered other issues later, was that I had around 190 materials at runtime that weren’t compiling because they were losing references to Material Functions. Unreal was then interpreting them as more basic materials, I think, which left the project exposed to potential future errors.

I tracked down the missing references and updated them, which fixed the issue with the ~190 materials that weren’t compiling.