Skip to content

Commit a061507

Browse files
JulienIgnace-UnityEvergreen
authored andcommitted
[Backport] Fixed a null ref exception when baking APV without GPU streaming enabled
Backport of https://github.cds.internal.unity3d.com/unity/unity/pull/41516
1 parent f989cc6 commit a061507

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,12 +1184,6 @@ static public void ApplyPostBakeOperations(NativeArray<SphericalHarmonicsL2> sh,
11841184

11851185
m_BakingBatchIndex = 0;
11861186

1187-
// Force maximum sh bands to perform baking, we need to store what sh bands was selected from the settings as we need to restore it after.
1188-
var prevSHBands = ProbeReferenceVolume.instance.shBands;
1189-
ProbeReferenceVolume.instance.ForceSHBand(ProbeVolumeSHBands.SphericalHarmonicsL2);
1190-
// Don't use Disk streaming to avoid having to wait for it when doing dilation.
1191-
ProbeReferenceVolume.instance.ForceNoDiskStreaming(true);
1192-
11931187
PrepareCellsForWriting(isBakingSceneSubset);
11941188

11951189
using var writeScope = new BakingCompleteProfiling(BakingCompleteProfiling.Stages.WriteBakedData);
@@ -1210,6 +1204,16 @@ static public void ApplyPostBakeOperations(NativeArray<SphericalHarmonicsL2> sh,
12101204
// Reset internal structures depending on current bake.
12111205
probeRefVolume.EnsureCurrentBakingSet(m_BakingSet);
12121206

1207+
// This subsequent block needs to happen AFTER we call WriteBakingCells.
1208+
// Otherwise in cases where we change the spacing between probes, we end up loading cells with a certain layout in ForceSHBand
1209+
// And then we unload cells using the wrong layout in PerformDilation (after WriteBakingCells updates the baking set object) which leads to a broken internal state.
1210+
1211+
// Don't use Disk streaming to avoid having to wait for it when doing dilation.
1212+
ProbeReferenceVolume.instance.ForceNoDiskStreaming(true);
1213+
// Force maximum sh bands to perform baking, we need to store what sh bands was selected from the settings as we need to restore it after.
1214+
var prevSHBands = ProbeReferenceVolume.instance.shBands;
1215+
ProbeReferenceVolume.instance.ForceSHBand(ProbeVolumeSHBands.SphericalHarmonicsL2);
1216+
12131217
// TODO Discuss: Not nice to do this here, shouldn't reloading the asset also resolve cell data?
12141218
// Would still need to reload common shared data like bricks as they are separately handled by the baking set itself.
12151219
// Load common shared data (bricks + debug)

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Streaming.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,10 @@ static int DefragComparer(Cell a, Cell b)
888888

889889
void StartIndexDefragmentation()
890890
{
891+
// We can end up here during baking (dilation) when trying to load all cells even without supporting GPU streaming.
892+
if (!m_SupportGPUStreaming)
893+
return;
894+
891895
m_IndexDefragmentationInProgress = true;
892896

893897
// Prepare the list of cells.

0 commit comments

Comments
 (0)