Skip to content

Commit cfa2936

Browse files
committed
Validate that an instance has been created, via the instanceExists bool prop in IEditingContext, before attempting to dispose in EditingContextManager's SetEditingContext() function
1 parent 21e7c2f commit cfa2936

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

Scripts/Core/Contexts/EditingContextManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ internal void SetEditingContext(IEditingContext context)
227227
if (s_CurrentContext != null)
228228
{
229229
m_PreviousContexts.Insert(0, s_CurrentContext);
230-
s_CurrentContext.Dispose();
230+
231+
if (s_CurrentContext.instanceExists)
232+
s_CurrentContext.Dispose();
231233
}
232234

233235
context.Setup();

Scripts/Core/Contexts/EditorVRContext.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class EditorVRContext : ScriptableObject, IEditingContext
2323

2424
public bool copySceneCameraSettings { get { return m_CopySceneCameraSettings; } }
2525

26+
public bool instanceExists { get { return m_Instance != null; } }
27+
2628
public void Setup()
2729
{
2830
EditorVR.defaultTools = m_DefaultToolStack.Select(ms => ms.GetClass()).ToArray();
@@ -32,12 +34,9 @@ public void Setup()
3234

3335
public void Dispose()
3436
{
35-
if (m_Instance)
36-
{
37-
m_Instance.Shutdown(); // Give a chance for dependent systems (e.g. serialization) to shut-down before destroying
38-
ObjectUtils.Destroy(m_Instance.gameObject);
39-
m_Instance = null;
40-
}
37+
m_Instance.Shutdown(); // Give a chance for dependent systems (e.g. serialization) to shut-down before destroying
38+
ObjectUtils.Destroy(m_Instance.gameObject);
39+
m_Instance = null;
4140
}
4241
}
4342
}

Scripts/Interfaces/Entity/IEditingContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public interface IEditingContext
1919
/// </summary>
2020
bool copySceneCameraSettings { get; }
2121

22+
/// <summary>
23+
/// Bool denotes that the EditorVR instance exists, having already been created in Setup()
24+
/// </summary>
25+
bool instanceExists { get; }
26+
2227
/// <summary>
2328
/// Perform one-time setup for the context when pushed to the stack.
2429
/// </summary>

0 commit comments

Comments
 (0)