Skip to content

Commit

Permalink
Add API restriction to fix a crash.
Browse files Browse the repository at this point in the history
It's very easy to create a crash when creating `Primitives` (e.g a Sphere) in a Custom Pass (HDRP). For example, by doing :
`GameObject.CreatePrimitive(PrimitiveType.Sphere);`

More context in the description of the PR: https://jira.unity3d.com/browse/UUM-2709

As explained from the JIRA ticket, indeed, this should be an illegal case. It seems to be already the case for many scenarios, since this API is used at many places:
`ApiRestrictions::RENDERERSCENE_ADDREMOVE`

After adding this restriction code, I can confirm the crash is gone. The behavior (creation of Primitives in a Custom Pass) still works well. 

Though, when starting the HDRP sample project, an error is logged two times in the Console, because of this code in HDRP:

```
// Because SRP rendering happens too late, we need to force the draw calls to update
RegisterLocalVolumetricFogEarlyUpdate.PrepareFogDrawCalls();
```

Since this DrawCall is triggered in the constructor of the `HDRenderPipeline` class, the newly added `APIRestriction` is triggered. 
I'm already chatting with @antoineL to determine if we could move this code after the constructor.

@torbjorn If think you are the initial reporter / investigator of this crash ? Let me know if you see any drawback regarding this solution. You definitely know this part of the code better than me.
  • Loading branch information
YohannVaastUnity authored and Evergreen committed Jun 14, 2024
1 parent 2c5a31a commit ad051f6
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,7 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c
RTHandles.SetReferenceSize(maxSize.x, maxSize.y);
}

ScriptableRenderContext.PushDisableApiRenderers();

// Execute render request graph, in reverse order
for (int i = 0; i < renderRequestIndicesToRender.Count; ++i)
Expand Down Expand Up @@ -2419,6 +2420,8 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c
CommandBufferPool.Release(cmd);
renderContext.Submit();
}

ScriptableRenderContext.PopDisableApiRenderers();
}
}
}
Expand Down

1 comment on commit ad051f6

@torbjorn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably mentioned the wrong @torbjorn , I have no association with this project. To my knowledge.

Please sign in to comment.