Skip to content

Commit

Permalink
Fix ArgumentNullException.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Nov 30, 2023
1 parent 6f56412 commit 193284b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions Editor/SelectIonTokenWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void ShowWindow(CesiumIonServer server)

public CesiumIonServer server;

private bool _initialize = false;
private IonTokenSource _source;
private string _createdTokenName = "";
private List<string> _existingTokenList = new List<string>();
Expand All @@ -46,21 +47,15 @@ public static string GetDefaultNewTokenName()

private void OnEnable()
{
CesiumIonSession session = CesiumIonServerManager.instance.GetSession(this.server);
session.Resume();
CesiumIonSession.OnTokensUpdated += this.RefreshTokens;

this._createdTokenName = GetDefaultNewTokenName();
this._specifiedToken = CesiumRuntimeSettings.defaultIonAccessToken;
this._source = session.IsConnected()
? IonTokenSource.Create
: IonTokenSource.Specify;

session.RefreshTokens();
// This gets called before we can possible set any properties on the new window,
// such as the `server` property. So instead of doing our initialization here,
// set a flag so we know to do it in OnGUI.
this._initialize = true;
}

private void OnDisable()
{
this._initialize = false;
CesiumIonSession.OnTokensUpdated -= this.RefreshTokens;
}

Expand Down Expand Up @@ -102,6 +97,24 @@ public string specifiedToken

private void OnGUI()
{
CesiumIonSession session = CesiumIonServerManager.instance.GetSession(this.server);

if (this._initialize)
{
session.Resume();
CesiumIonSession.OnTokensUpdated += this.RefreshTokens;

this._createdTokenName = GetDefaultNewTokenName();
this._specifiedToken = CesiumRuntimeSettings.defaultIonAccessToken;
this._source = session.IsConnected()
? IonTokenSource.Create
: IonTokenSource.Specify;

session.RefreshTokens();

this._initialize = false;
}

GUILayout.Space(10);
EditorGUILayout.LabelField(
"Cesium for Unity embeds a Cesium ion token in your project in " +
Expand All @@ -110,7 +123,6 @@ private void OnGUI()
EditorStyles.wordWrappedLabel
);

CesiumIonSession session = CesiumIonServerManager.instance.GetSession(this.server);
if (session.IsConnected())
{
GUILayout.Space(20);
Expand Down

0 comments on commit 193284b

Please sign in to comment.