Skip to content

Commit 19f3806

Browse files
catch thrown errors in PPv2 Render (case 1221972) (#5218)
* catch thrown errors in PPv2 Render (case 1221972) * Correction, we use 3.1.2 version currently Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent cf0b05d commit 19f3806

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

Diff for: com.unity.postprocessing/CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [3.1.2] - 2021-02-06
88

9-
Version Updated
10-
The version number for this package has increased due to a version update of a related graphics package.
9+
### Fixed
10+
- Catch thrown errors in `PostProcessEffectRenderer`, preventing resources allocation leaks and crash (case 1221972)
1111

1212
## [3.1.1] - 2021-03-08
1313

Diff for: com.unity.postprocessing/PostProcessing/Runtime/PostProcessLayer.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ void BuildCommandBuffers()
607607

608608
if (isScreenSpaceReflectionsActive)
609609
{
610-
ssrRenderer.Render(context);
610+
ssrRenderer.RenderOrLog(context);
611611
opaqueOnlyEffects--;
612612
UpdateSrcDstForOpaqueOnly(ref srcTarget, ref dstTarget, context, cameraTarget, opaqueOnlyEffects);
613613
}
@@ -1125,7 +1125,7 @@ void RenderList(List<SerializedBundleRef> list, PostProcessRenderContext context
11251125
// If there's only one active effect, we can simply execute it and skip the rest
11261126
if (count == 1)
11271127
{
1128-
m_ActiveEffects[0].Render(context);
1128+
m_ActiveEffects[0].RenderOrLog(context);
11291129
}
11301130
else
11311131
{
@@ -1150,7 +1150,7 @@ void RenderList(List<SerializedBundleRef> list, PostProcessRenderContext context
11501150
{
11511151
context.source = m_Targets[i];
11521152
context.destination = m_Targets[i + 1];
1153-
m_ActiveEffects[i].Render(context);
1153+
m_ActiveEffects[i].RenderOrLog(context);
11541154
}
11551155

11561156
cmd.ReleaseTemporaryRT(tempTarget1);
@@ -1373,15 +1373,15 @@ int RenderEffect<T>(PostProcessRenderContext context, bool useTempTarget = false
13731373

13741374
if (!useTempTarget)
13751375
{
1376-
effect.renderer.Render(context);
1376+
effect.renderer.RenderOrLog(context);
13771377
return -1;
13781378
}
13791379

13801380
var finalDestination = context.destination;
13811381
var tempTarget = m_TargetPool.Get();
13821382
context.GetScreenSpaceTemporaryRT(context.command, tempTarget, 0, context.sourceFormat);
13831383
context.destination = tempTarget;
1384-
effect.renderer.Render(context);
1384+
effect.renderer.RenderOrLog(context);
13851385
context.source = tempTarget;
13861386
context.destination = finalDestination;
13871387
return tempTarget;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
3+
namespace UnityEngine.Rendering.PostProcessing
4+
{
5+
static class PostProcessEffectRendererExtensions
6+
{
7+
/// <summary>
8+
/// Render with a try catch for all exception.
9+
///
10+
/// If an exception occurs during the <see cref="PostProcessEffectRenderer.Render"/> call, it will be logged
11+
/// and returned.
12+
///
13+
/// Use this method instead of <see cref="PostProcessEffectRenderer.Render"/> in critical contexts
14+
/// to avoid entering the exception flow.
15+
/// </summary>
16+
/// <param name="self">The renderer to render.</param>
17+
/// <param name="context">A context object</param>
18+
/// <returns></returns>
19+
public static Exception RenderOrLog(this PostProcessEffectRenderer self, PostProcessRenderContext context)
20+
{
21+
try
22+
{
23+
self.Render(context);
24+
}
25+
catch (Exception e)
26+
{
27+
Debug.LogException(e);
28+
return e;
29+
}
30+
31+
return null;
32+
}
33+
}
34+
}

Diff for: com.unity.postprocessing/PostProcessing/Runtime/Utils/PostProcessEffectRendererExtensions.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)