Crash due to race condition in AddDeferredDecalPass while using Mobile Renderer

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]

Hi Kevin,

This seems to be an acceptable workaround for this case. You may also want to look at CL 49933004 which transitioned the mobile renderer to use a decal visibility task, similarly to the desktop renderer.

Best regards.

[Attachment Removed]

Thank you for the tip on the CL that changes the task scheduling around this.

It looks like I might have to take CL 50450106 and CL 50491548 as well if we adopt that solution. Are these the only additional CLs I might need in this case?

[Attachment Removed]

Hi Kevin,

Yes, those two CLs appear to provide follow up fixes to the initial transition to the decal visibility task.

Best regards.

[Attachment Removed]