FirstGearGames / FishNet

FishNet: Unity Networking Evolved.
Other
1.39k stars 149 forks source link

ResettableRingBuffer error. When nob despawn. #781

Closed Danila24ru closed 4 weeks ago

Danila24ru commented 2 months ago

General Unity version: 2022.3.30f1 Fish-Networking version: 4.4.6R Discord link: https://discord.com/channels/424284635074134018/1034477094731784302/1287814642969743493

Description Sometimes error occurs: Index 0 is out of range. Collection count is 0, Capacity is 1 when despawn network objects.

Replication Steps to reproduce the behavior:

  1. Create prefab objects with NetworkCollider2D + PhysicsPrediction2D
  2. Spawn 30 objects every frame with _networkManager.GetPooledInstantiated(prefab.gameObject, position, rotation, true);
  3. Despawn 30 objects every frame with nob.Despawn(DespawnType.Pool);

Expected behavior No errors on despawn..

Logs

UnityEngine.Debug:LogError (object)
GameKit.Dependencies.Utilities.Types.ResettableRingBuffer`1<FishNet.Component.Prediction.NetworkCollider2D/Collider2DData>:<GetRealIndex>g__ReturnError|29_0 (GameKit.Dependencies.Utilities.Types.ResettableRingBuffer`1/<>c__DisplayClass29_0<FishNet.Component.Prediction.NetworkCollider2D/Collider2DData>&) (at Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Types/ResettableRingBuffer.cs:400)
GameKit.Dependencies.Utilities.Types.ResettableRingBuffer`1<FishNet.Component.Prediction.NetworkCollider2D/Collider2DData>:GetRealIndex (int,bool) (at Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Types/ResettableRingBuffer.cs:389)
GameKit.Dependencies.Utilities.Types.ResettableRingBuffer`1/Enumerator<FishNet.Component.Prediction.NetworkCollider2D/Collider2DData>:Initialize (GameKit.Dependencies.Utilities.Types.ResettableRingBuffer`1<FishNet.Component.Prediction.NetworkCollider2D/Collider2DData>) (at Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Types/ResettableRingBuffer.cs:82)
GameKit.Dependencies.Utilities.Types.ResettableRingBuffer`1<FishNet.Component.Prediction.NetworkCollider2D/Collider2DData>:GetEnumerator () (at Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Types/ResettableRingBuffer.cs:478)
FishNet.Component.Prediction.NetworkCollider2D:ClearColliderDataHistory () (at Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollider2D.cs:500)
FishNet.Component.Prediction.NetworkCollider2D:ResetState (bool) (at Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollider2D.cs:492)
FishNet.Object.NetworkObject:ResetState (bool) (at Assets/FishNet/Runtime/Object/NetworkObject.cs:1005)
FishNet.Utility.Performance.DefaultObjectPool:StoreObject (FishNet.Object.NetworkObject,bool) (at Assets/FishNet/Runtime/Utility/Performance/DefaultObjectPool.cs:162)
FishNet.Managing.NetworkManager:StorePooledInstantiated (FishNet.Object.NetworkObject,bool) (at Assets/FishNet/Runtime/Managing/NetworkManager.ObjectPooling.cs:108)
FishNet.Managing.Object.ManagedObjects:Despawn (FishNet.Object.NetworkObject,FishNet.Object.DespawnType,bool) (at Assets/FishNet/Runtime/Managing/Object/ManagedObjects.cs:175)
FishNet.Managing.Server.ServerObjects:Despawn (FishNet.Object.NetworkObject,FishNet.Object.DespawnType,bool) (at Assets/FishNet/Runtime/Managing/Server/Object/ServerObjects.cs:918)
FishNet.Managing.Server.ServerManager:Despawn (FishNet.Object.NetworkObject,System.Nullable`1<FishNet.Object.DespawnType>) (at Assets/FishNet/Runtime/Managing/Server/ServerManager.QOL.cs:150)
FishNet.Object.NetworkObject:Despawn (System.Nullable`1<FishNet.Object.DespawnType>) (at Assets/FishNet/Runtime/Object/NetworkObject.QOL.cs:273)
FishNet.Object.NetworkBehaviour:Despawn (System.Nullable`1<FishNet.Object.DespawnType>) (at Assets/FishNet/Runtime/Object/NetworkBehaviour.QOL.cs:224)
_Project.Scripts.Game.Abilities.DeadAbility/<Process>d__1:MoveNext () (at Assets/_Project/Scripts/Game/Abilities/DeadAbility.cs:19)
Danila24ru commented 2 months ago

note: Despawn(DespawnType.Pool) called in NetworkCollision2D.OnEnter += OnCollide callback.

FirstGearGames commented 2 months ago

Can you make a tiny project on replicating this please.

https://fish-networking.gitbook.io/docs/manual/guides/creating-bug-reports

See ^ for full steps.

Orgil commented 2 months ago

Just updated from 4.4.5 to 4.4.6. i do have same error.

FirstGearGames commented 2 months ago

I won't be able to troubleshoot this without a repo project.

Dyobon commented 1 month ago

Changing ResettableRingBuffer.cs line 82 from "_startIndex = c.GetRealIndex(0);" to "_startIndex = c.GetRealIndex(0, true);" solved it for me. Don't know if that change can cascade in any other issues.

FirstGearGames commented 1 month ago

That's definitely not a solution. That would cause incorrect results to be returned. I strongly recommend someone upload a small test project so this can be fixed properly.

FirstGearGames commented 1 month ago

Queued to close in 2 weeks if there is no new activity.