Skip to content

Commit 5d9c6f0

Browse files
author
Robert Onulak
committed
Fix DirectPairing from crashing the editor and application if the script execution order calls SharingStage's OnDestroy first.
1 parent 295ff75 commit 5d9c6f0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Assets/HoloToolkit/Sharing/Scripts/Utilities/DirectPairing.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ void Start()
6363

6464
void OnDestroy()
6565
{
66-
if (this.sharingMgr != null)
66+
// SharingStage's OnDestroy() might execute first in the script order. Therefore we should check if
67+
// SharingStage.Instance still exists. Without the instance check, the execution of GetPairingManager
68+
// on a disposed sharing manager will crash the Unity Editor and application.
69+
if (SharingStage.Instance != null && this.sharingMgr != null)
6770
{
6871
PairingManager pairingMgr = sharingMgr.GetPairingManager();
6972
pairingMgr.CancelPairing(); // Safe to call, even if no pairing is in progress. Will not cause a disconnect

0 commit comments

Comments
 (0)