FirstGearGames / FishNet

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

Error from DebugManager's Write Scene Object Details option #642

Closed maxkratt closed 6 months ago

maxkratt commented 7 months ago

General Unity version: 2021.3.33f1 Fish-Networking version: 4.1.6 Discord link: https://discord.com/channels/424284635074134018/1217847853314080820/1217907567456424006 Credit to rikusen0335 for creating the original example.

Description Using the DebugManager's "Write Scene Object Details" option can in some cases produce the following error:

ArgumentOutOfRangeException: ArgumentOutOfRange_NeedNonNegNum
Parameter name: count
System.ArraySegment`1[T]..ctor (System.Byte[] array, System.Int32 offset, System.Int32 count) (at <7e05db41a20b45108859fa03b97088d4>:0)
FishNet.Serializing.Reader.ReadArraySegment (System.Int32 count) (at Assets/FishNet/Runtime/Serializing/Reader.cs:381)
FishNet.Managing.Client.ClientObjects.CacheSpawn (FishNet.Serializing.PooledReader reader) (at Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.cs:447)
FishNet.Managing.Client.ClientManager.ParseReader (FishNet.Serializing.PooledReader reader, FishNet.Transporting.Channel channel, System.Boolean print) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:426)
FishNet.Managing.Client.ClientManager.ParseReceived (FishNet.Transporting.ClientReceivedDataArgs args) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:370)
FishNet.Managing.Client.ClientManager.Transport_OnClientReceivedData (FishNet.Transporting.ClientReceivedDataArgs args) (at Assets/FishNet/Runtime/Managing/Client/ClientManager.cs:328)
FishNet.Transporting.Tugboat.Tugboat.HandleClientReceivedDataArgs (FishNet.Transporting.ClientReceivedDataArgs receivedDataArgs) (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Tugboat.cs:238)
FishNet.Transporting.Tugboat.Client.ClientSocket.IterateIncoming () (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Core/ClientSocket.cs:295)
FishNet.Transporting.Tugboat.Tugboat.IterateIncoming (System.Boolean server) (at Assets/FishNet/Runtime/Transporting/Transports/Tugboat/Tugboat.cs:211)
FishNet.Managing.Transporting.TransportManager.IterateIncoming (System.Boolean server) (at Assets/FishNet/Runtime/Managing/Transporting/TransportManager.cs:708)
FishNet.Managing.Timing.TimeManager.TryIterateData (System.Boolean incoming) (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:1066)
FishNet.Managing.Timing.TimeManager.IncreaseTick () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:718)
FishNet.Managing.Timing.TimeManager.<TickUpdate>g__MethodLogic|97_0 () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:390)
FishNet.Managing.Timing.TimeManager.TickUpdate () (at Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs:380)
FishNet.Transporting.NetworkReaderLoop.Update () (at Assets/FishNet/Runtime/Transporting/NetworkReaderLoop.cs:28)

Replication Steps to reproduce the behavior:

  1. Import example package
  2. Add the example scene to the build settings
  3. Build and run the game. It will start as a host.
  4. Press play in the Unity editor and it will start as a client
  5. The error should get logged in the unity editor console

Example File DebugManagerError.zip

Video

https://github.com/FirstGearGames/FishNet/assets/60508288/5e6b8b4a-db52-4c61-b8b8-0594010c79b6

FirstGearGames commented 6 months ago

There was no error displayed when building as development mode. The DebugManager is non-functioning when building as release. So the client is expecting debug, but the server is not sending it as intended. Let me know if I'm missing anything!

SackMaggie commented 6 months ago

The bug is happen in release build connect to a development build.

https://discord.com/channels/424284635074134018/1034477094731784302/1231127923050680330

SackMaggie commented 6 months ago

FishNet.Managing.Object.ManagedObjects.WriteSpawn_Server(NetworkObject nob, NetworkConnection connection, Writer writer) `#if DEVELOPMENT //Check to write additional information if a scene object. if (NetworkManager.DebugManager.WriteSceneObjectDetails) { headerWriter.WriteString(nob.gameObject.scene.name); headerWriter.WriteString(nob.gameObject.name); }

endif`

FishNet.Managing.Client.ClientObjects.WriteSpawn_Client(NetworkObject nob, Writer writer) ` if (sceneObject) { headerWriter.WriteUInt64(nob.SceneId, AutoPackType.Unpacked);

if DEVELOPMENT

            base.CheckWriteSceneObjectDetails(nob, headerWriter);

endif

        }`

Reader FishNet.Managing.Client.ClientObjects.CacheSpawn(PooledReader reader) ` if (sceneObject) { ReadSceneObject(reader, out sceneId);

if UNITY_EDITOR || DEVELOPMENT_BUILD

            base.CheckReadSceneObjectDetails(reader, ref sceneName, ref objectName);

endif

        }`

Notice the different in reading and writing ? The #if is different and does not cover the case release build connect to dev build. If different build connect is an intended behaviour, At least it should be noted somewhere ?

Here's where it wrote packet in picture image image

Here's where it read image

I'm actually not sure if there's more issue similar to this case where like 'working in editor but outright fail in release build' "just build two release build" should be the solution but no, I think there's more issue in dedicated server build.

FirstGearGames commented 6 months ago

That's normal. Debug code doesn't run in release builds so the builds are different.

On Sat, May 4, 2024, 5:34 PM SackMaggie @.***> wrote:

The bug is happen in release build connect to a development build.

https://discord.com/channels/424284635074134018/1034477094731784302/1231127923050680330

— Reply to this email directly, view it on GitHub https://github.com/FirstGearGames/FishNet/issues/642#issuecomment-2094404135, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGPJC3U5WSOMWEWHMZRIB3TZAVH4PAVCNFSM6AAAAABF2T5V5CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJUGQYDIMJTGU . You are receiving this because you modified the open/close state.Message ID: @.***>

SackMaggie commented 6 months ago

Alright If you said so, But to prevent this issue there should be some error printing when client connect and on a different build that hey this is not supported, should save a lot of frustration/time.

FirstGearGames commented 6 months ago

I agree. I was actually thinking about this moments after your previous comment. I've done just this for the FishNet version in the next release, I can piggyback off the same code for this too.

FirstGearGames commented 6 months ago

Added and tested working in next release, 4.3.0