Skip to content

Commit 4888c12

Browse files
authored
Fix bug where the layers panel doesn't init if it's not open when a sketch is loaded (#854)
* Wrong l10n ref for alt save button * No reason for this to be public * Move event handlers to awake/destroy * Handle a potential edge case and add comments
1 parent e0f2157 commit 4888c12

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Assets/Prefabs/Panels/AdminPanel.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ MonoBehaviour:
420420
m_TableReference:
421421
m_TableCollectionName: GUID:c84355079ab3f3e4f8f3812258805f86
422422
m_TableEntryReference:
423-
m_KeyId: 312729904472465408
423+
m_KeyId: 312730512516521984
424424
m_Key:
425425
m_FallbackState: 0
426426
m_WaitForCompletion: 0

Assets/Scripts/Layers/LayerUI_Manager.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public class LayerUI_Manager : MonoBehaviour
2929
[SerializeField] private LocalizedString m_AdditionalLayerName;
3030
[SerializeField] private NavButton m_PreviousPageButton;
3131
[SerializeField] private NavButton m_NextPageButton;
32+
[SerializeField] private List<GameObject> m_Widgets;
3233

33-
public List<GameObject> m_Widgets;
3434
private List<CanvasScript> m_Canvases;
3535
private int m_StartingCanvasIndex;
3636
private bool m_RefreshNavButtons;
@@ -48,6 +48,9 @@ private void Start()
4848

4949
private void ResetUI()
5050
{
51+
// TODO: We're probably calling this too much during sketch load
52+
// But it's not a huge performance hog so we'll leave it for now
53+
5154
m_Canvases = App.Scene.LayerCanvases.ToList();
5255

5356
for (int i = 0; i < m_Widgets.Count; i++)
@@ -97,14 +100,14 @@ private void OnLayerCanvasesUpdate()
97100
}
98101

99102
// Subscribes to events
100-
private void OnEnable()
103+
private void Awake()
101104
{
102105
App.Scene.ActiveCanvasChanged += ActiveSceneChanged;
103106
App.Scene.LayerCanvasesUpdate += OnLayerCanvasesUpdate;
104107
}
105108

106109
// Unsubscribes to events
107-
private void OnDisable()
110+
private void OnDestroy()
108111
{
109112
App.Scene.ActiveCanvasChanged -= ActiveSceneChanged;
110113
App.Scene.LayerCanvasesUpdate -= OnLayerCanvasesUpdate;

Assets/Scripts/Save/SketchWriter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,16 @@ public static IEnumerable<AdjustedMemoryBrushStroke> EnumerateAdjustedSnapshots(
172172
snapshot.layerIndex = canvasToIndexMap[stroke.Canvas];
173173
yield return snapshot;
174174
}
175+
else if (stroke.IsGeometryEnabled && !canvasToIndexMap.ContainsKey(stroke.Canvas))
176+
{
177+
// This shouldn't happen
178+
Debug.Log($"Skipping layerless stroke {stroke.m_BrushGuid}");
179+
snapshot.layerIndex = canvasToIndexMap[App.Scene.MainCanvas];
180+
yield return snapshot;
181+
}
175182
else
176183
{
184+
Debug.Log($"Skipping inactive stroke {stroke.m_BrushGuid}");
177185
// Effectively, if the lead stroke of group is inactive (erased), we promote
178186
// subsequent strokes to lead until one such stroke is active.
179187
resetGroupContinue = !snapshot.adjustedStrokeFlags.HasFlag(StrokeFlags.IsGroupContinue);

0 commit comments

Comments
 (0)