This question was created in reference to: [Crash Issue During Deferred Decal Rendering on [Content removed]
Hello,
Thank you for your continued support.
We found a fix for the issue reported in the ticket and it looks like the issue comes from the FVisibleDecalList variable just before being called in FMobileSceneRenderer::RenderDBuffer has a race condition due to the scope.
AddDeferredDecalPass creates an async RDG task which captures the SortedDecals ArrayView containing to pointers to entries in the VisibleDecals list. However, there are situations where the VisibleDecals list goes out scope by the time the RDG task gets executed and ends up working on invalid memory causing a crash.
The fix we found is to create the VisibleDecals list using the GraphBuilder allocation helper to keep the memory around until the GraphBuilder object remains.
This seems to be an issue only in the Mobile Renderer since the visible decals list in the Desktop Renderer is maintained as part of the FDecalVisibilityViewPacket whose memory is backed by the GraphBuilder allocator as expected.
Please let us know if this helps and if you see any concerns in doing this change.
void FMobileSceneRenderer::RenderDBuffer(..)
{
...
// CHANGES BEGIN
// FVisibleDecalList VisibleDecals = DecalRendering::BuildVisibleDecalList(Scene->Decals, View);
FVisibleDecalList* VisibleDecals = GraphBuilder.AllocObject<FVisibleDecalList>(DecalRendering::BuildVisibleDecalList(Scene->Decals, View));
FRelevantDecalList SortedDecals = DecalRendering::BuildRelevantDecalList(*VisibleDecals, EDecalRenderStage::BeforeBasePass);
// CHANGES END
[Attachment Removed]