Skip to content

Commit 7ca8f19

Browse files
committed
Code review comments
1 parent c319570 commit 7ca8f19

5 files changed

Lines changed: 20 additions & 18 deletions

File tree

‎com.unity.netcode.gameobjects/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
1818

1919
### Fixed
2020

21+
- Ensured all callbacks are wrapped with exception handling to avoid silent errors. (#4161)
22+
2123
### Security
2224

2325
### Obsolete

‎com.unity.netcode.gameobjects/Documentation~/upgrade-guide.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To upgrade an existing project from version 2.x to version 3.x, follow these ste
2626
4. The API updater should catch any issues and ask if you want to allow it to make changes to your script(s).
2727
5. If you allow the API updater to make changes for you, then it should auto-update your project's scripts with the correct namespace changes.
2828
6. If you do not allow the API updater to make changes for you, then the editor will enter safe mode. Open the **Console** window to review the remaining compile errors and resolve the errors. (_[Review the Update Editor assembly definition references section below.](#update-editor-assembly-definition-references)_).
29-
29+
3030
After the API updater finishes and you resolve the compile errors, your project compiles against version 3.x. If the API updater doesn't resolve every reference, refer to [Continue an incomplete API update](#continue-an-incomplete-api-update).
3131

3232
_** If, at any point, you decide to downgrade to the editor version you were using prior to updating to 6.7, then make sure to restore or delete the packages-lock.json file (_assures you are not referencing 6.7 specific packages_), restore your backed up version, and delete your Library folder prior to opening your project with the editor version you were using prior to upgrading to 6.7._

‎com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,9 @@ internal bool InternalStartServer()
15011501
catch (Exception ex)
15021502
{
15031503
Log.Exception(ex);
1504+
// Shutdown on exception to assure everything is cleaned up correctly
1505+
ShutdownInternal();
1506+
return false;
15041507
}
15051508
ConnectionManager.LocalClient.IsApproved = true;
15061509
return true;
@@ -1584,6 +1587,9 @@ internal bool InternalStartClient()
15841587
catch (Exception ex)
15851588
{
15861589
Log.Exception(ex);
1590+
// Shutdown on exception to assure everything is cleaned up correctly
1591+
ShutdownInternal();
1592+
return false;
15871593
}
15881594
}
15891595
}
@@ -1705,16 +1711,10 @@ private void HostServerInitialize()
17051711
// Notify the host that everything should be synchronized/spawned at this time.
17061712
SpawnManager.NotifyNetworkObjectsSynchronized();
17071713

1708-
try
1709-
{
1710-
OnServerStarted?.Invoke();
1711-
OnClientStarted?.Invoke();
1712-
OnStarted?.Invoke();
1713-
}
1714-
catch (Exception ex)
1715-
{
1716-
Log.Exception(ex);
1717-
}
1714+
// No need to try/catch these callbacks because this function is already wrapped.
1715+
OnServerStarted?.Invoke();
1716+
OnClientStarted?.Invoke();
1717+
OnStarted?.Invoke();
17181718

17191719
// This assures that any in-scene placed NetworkObject is spawned and
17201720
// any associated NetworkBehaviours' netcode related properties are

‎com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,11 @@ public enum OwnershipPermissionsFailureStatus
818818
public OnOwnershipPermissionsFailureDelegateHandler OnOwnershipPermissionsFailure;
819819

820820

821-
internal void InvokeOwnershipPermissionsFailure()
821+
internal void InvokeOwnershipPermissionsFailure(OwnershipPermissionsFailureStatus failureStatus)
822822
{
823823
try
824824
{
825-
OnOwnershipPermissionsFailure?.Invoke(OwnershipPermissionsFailureStatus.SessionOwnerOnly);
825+
OnOwnershipPermissionsFailure?.Invoke(failureStatus);
826826
}
827827
catch (Exception ex)
828828
{

‎com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ internal void ChangeOwnership(NetworkObject networkObject, ulong clientId, bool
522522
{
523523
NetworkLog.LogErrorServer($"[{networkObject.name}][Session Owner Only] You cannot change ownership of a {nameof(NetworkObject)} that has the {NetworkObject.OwnershipStatus.SessionOwner} flag set!");
524524
}
525-
networkObject.InvokeOwnershipPermissionsFailure();
525+
networkObject.InvokeOwnershipPermissionsFailure(NetworkObject.OwnershipPermissionsFailureStatus.SessionOwnerOnly);
526526
return;
527527
}
528528

@@ -535,7 +535,7 @@ internal void ChangeOwnership(NetworkObject networkObject, ulong clientId, bool
535535
{
536536
NetworkLog.LogErrorServer($"[{networkObject.name}][Locked] You cannot change ownership while a {nameof(NetworkObject)} is locked!");
537537
}
538-
networkObject.InvokeOwnershipPermissionsFailure();
538+
networkObject.InvokeOwnershipPermissionsFailure(NetworkObject.OwnershipPermissionsFailureStatus.Locked);
539539
return;
540540
}
541541
if (networkObject.IsRequestInProgress)
@@ -544,7 +544,7 @@ internal void ChangeOwnership(NetworkObject networkObject, ulong clientId, bool
544544
{
545545
NetworkLog.LogErrorServer($"[{networkObject.name}][Request Pending] You cannot change ownership while a {nameof(NetworkObject)} has a pending ownership request!");
546546
}
547-
networkObject.InvokeOwnershipPermissionsFailure();
547+
networkObject.InvokeOwnershipPermissionsFailure(NetworkObject.OwnershipPermissionsFailureStatus.RequestInProgress);
548548
return;
549549
}
550550
if (networkObject.IsOwnershipRequestRequired)
@@ -553,7 +553,7 @@ internal void ChangeOwnership(NetworkObject networkObject, ulong clientId, bool
553553
{
554554
NetworkLog.LogErrorServer($"[{networkObject.name}][Request Required] You cannot change ownership directly if a {nameof(NetworkObject)} has the {NetworkObject.OwnershipStatus.RequestRequired} flag set!");
555555
}
556-
networkObject.InvokeOwnershipPermissionsFailure();
556+
networkObject.InvokeOwnershipPermissionsFailure(NetworkObject.OwnershipPermissionsFailureStatus.RequestRequired);
557557
return;
558558
}
559559
if (!networkObject.IsOwnershipTransferable)
@@ -562,7 +562,7 @@ internal void ChangeOwnership(NetworkObject networkObject, ulong clientId, bool
562562
{
563563
NetworkLog.LogErrorServer($"[{networkObject.name}][Not transferrable] You cannot change ownership of a {nameof(NetworkObject)} that does not have the {NetworkObject.OwnershipStatus.Transferable} flag set!");
564564
}
565-
networkObject.InvokeOwnershipPermissionsFailure();
565+
networkObject.InvokeOwnershipPermissionsFailure(NetworkObject.OwnershipPermissionsFailureStatus.NotTransferrable);
566566
return;
567567
}
568568
}

0 commit comments

Comments
 (0)