Skip to content

Fix object disappearing from lookdev #5063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion com.unity.render-pipelines.core/Editor/LookDev/LookDev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine.Rendering.LookDev;
using UnityEditorInternal;
using UnityEngine;
using System.Linq;

namespace UnityEditor.Rendering.LookDev
{
Expand Down Expand Up @@ -32,6 +33,11 @@ internal static Context currentContext
{
if (s_CurrentContext == null || s_CurrentContext.Equals(null))
{
// In case the context is still alive somewhere but the static reference has been lost, we can find the object back with this
s_CurrentContext = TryFindCurrentContext();
if (s_CurrentContext != null)
return s_CurrentContext;

s_CurrentContext = LoadConfigInternal();
if (s_CurrentContext == null)
s_CurrentContext = defaultContext;
Expand All @@ -43,11 +49,22 @@ internal static Context currentContext
private set => s_CurrentContext = value;
}

static Context TryFindCurrentContext()
{
Context context = s_CurrentContext;

if (context != null)
return context;

return Resources.FindObjectsOfTypeAll<Context>().FirstOrDefault();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be sure that we not load a context that should be garbage collected ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure to see why it matters?

In any case, the static field is cleared after the domain reload, if the ScriptableObject survived the domain reload, then I expect it to never be garbage collected.

}

static Context defaultContext
{
get
{
var context = UnityEngine.ScriptableObject.CreateInstance<Context>();
context.hideFlags = HideFlags.HideAndDontSave;
context.Init();
return context;
}
Expand Down Expand Up @@ -132,7 +149,7 @@ internal static void Initialize(DisplayWindow window)

// Lookdev Initialize can be called when the window is re-created by the editor layout system.
// In that case, the current context won't be null and there might be objects to reload from the temp ID
ConfigureLookDev(reloadWithTemporaryID: s_CurrentContext != null);
ConfigureLookDev(reloadWithTemporaryID: TryFindCurrentContext() != null);
}

[Callbacks.DidReloadScripts]
Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed wobbling/tearing-like artifacts with SSAO.
- Fixed white flash with SSR when resetting camera history (case 1335263).
- Fixed VFX flag "Exclude From TAA" not working for some particle types.
- Fixed objects disappearing from Lookdev window when entering playmode (case 1309368).

### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
Expand Down