Skip to content

Commit

Permalink
[Port][2021.3][RG Viewer] Make sure the RG events are not unsubscribe…
Browse files Browse the repository at this point in the history
…d when comming back from a Maximized state

The `OnDisable` is called just after the on Enable when coming back from a Maximized state. Making events unsubscribed.
  • Loading branch information
alex-vazquez-unity3d authored and Evergreen committed May 30, 2024
1 parent cb86053 commit 7db7612
Showing 1 changed file with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,7 @@ void OnEnable()
foreach (var graph in registeredGraph)
m_RegisteredGraphs.Add(graph, new HashSet<string>());

RenderGraph.requireDebugData = true;
RenderGraph.onGraphRegistered += OnGraphRegistered;
RenderGraph.onGraphUnregistered += OnGraphUnregistered;
RenderGraph.onExecutionRegistered += OnExecutionRegistered;
RenderGraph.onExecutionUnregistered += OnExecutionUnregistered;
SubscribeToRenderGraphEvents();
}

private void CreateGUI()
Expand All @@ -690,10 +686,36 @@ private void CreateGUI()

void OnDisable()
{
UnsubscribeToRenderGraphEvents();
}

void SubscribeToRenderGraphEvents()
{
if (RenderGraph.requireDebugData)
return;

RenderGraph.requireDebugData = true;
RenderGraph.onGraphRegistered += OnGraphRegistered;
RenderGraph.onGraphUnregistered += OnGraphUnregistered;
RenderGraph.onExecutionRegistered += OnExecutionRegistered;
RenderGraph.onExecutionUnregistered += OnExecutionUnregistered;
}

void UnsubscribeToRenderGraphEvents()
{
if (!RenderGraph.requireDebugData)
return;

RenderGraph.requireDebugData = false;
RenderGraph.onGraphRegistered -= OnGraphRegistered;
RenderGraph.onGraphUnregistered -= OnGraphUnregistered;
RenderGraph.onExecutionRegistered -= OnExecutionRegistered;
RenderGraph.onExecutionUnregistered -= OnExecutionUnregistered;
}

void Update()
{
// UUM-70378: In case the OnDisable Unsubscribes to Render Graph events when coming back from a Maximized state
SubscribeToRenderGraphEvents();
}
}

0 comments on commit 7db7612

Please sign in to comment.