Skip to content

Commit 3f62415

Browse files
liamcaryLiam Carymiwarnec
authored
fix(NetworkInformationPreview): NRE in constructor (#4034)
* Fix EditorStyles.label causing NRE in NetworkInformationPreview implicit constructor * Update Assets/Mirror/Editor/NetworkInformationPreview.cs --------- Co-authored-by: Liam Cary <[email protected]> Co-authored-by: mischa <[email protected]>
1 parent 015aec1 commit 3f62415

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Assets/Mirror/Editor/NetworkInformationPreview.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ public Styles()
6060
}
6161

6262
GUIContent title;
63-
Styles styles = new Styles();
63+
64+
// Lazy-init fixes NullReferenceException from Styles.labelStyle accessing EditorStyles.label before unity initialises EditorStyles.s_Current
65+
// https://github.com/MirrorNetworking/Mirror/pull/4034
66+
Styles _styles;
67+
Styles styles => _styles ?? (_styles = new Styles());
6468

6569
public override GUIContent GetPreviewTitle()
6670
{
@@ -95,10 +99,6 @@ public override void OnPreviewGUI(Rect r, GUIStyle background)
9599
if (identity == null)
96100
return;
97101

98-
if (styles == null)
99-
styles = new Styles();
100-
101-
102102
// padding
103103
RectOffset previewPadding = new RectOffset(-5, -5, -5, -5);
104104
Rect paddedr = previewPadding.Add(r);

0 commit comments

Comments
 (0)