Skip to content

OverflowException: Value was either too large or too small for an Int32. #247

Open
@sasalicat

Description

@sasalicat

Meet this error when running unity sdk example,heres stack: OverflowException: Value was either too large or too small for an Int32. System.Convert.ToInt32 (System.Double value) (at <7ec8e29954a6455daa48484a381ec418>:0) System.Convert.ToInt32 (System.Single value) (at <7ec8e29954a6455daa48484a381ec418>:0) Colyseus.Schema.Decoder1[T].DecodeValue (System.Byte[] bytes, Colyseus.Schema.Iterator it, Colyseus.Schema.IRef _ref, System.Int32 fieldIndex, System.String fieldType, System.Type childType, System.Byte operation, System.Object& value, System.Object& previousValue) (at ./Library/PackageCache/io.colyseus.sdk@970cbca8b8/Runtime/Colyseus/Serializer/Schema/Decoder.cs:177)
Colyseus.Schema.Decoder1[T].DecodeSchema (System.Byte[] bytes, Colyseus.Schema.Iterator it, Colyseus.Schema.Schema refSchema) (at ./Library/PackageCache/io.colyseus.sdk@970cbca8b8/Runtime/Colyseus/Serializer/Schema/Decoder.cs:239) Colyseus.Schema.Decoder1[T].Decode (System.Byte[] bytes, Colyseus.Schema.Iterator it) (at ./Library/PackageCache/io.colyseus.sdk@970cbca8b8/Runtime/Colyseus/Serializer/Schema/Decoder.cs:74)
Colyseus.ColyseusSchemaSerializer1[T].SetState (System.Byte[] data, System.Int32 offset) (at ./Library/PackageCache/io.colyseus.sdk@970cbca8b8/Runtime/Colyseus/Serializer/SchemaSerializer.cs:26) Colyseus.ColyseusRoom1[T].SetState (System.Byte[] encodedState, System.Int32 offset) (at ./Library/PackageCache/io.colyseus.sdk@970cbca8b8/Runtime/Colyseus/Room/ColyseusRoom.cs:237)
Colyseus.ColyseusRoom`1[T].ParseMessage (System.Byte[] bytes) (at ./Library/PackageCache/io.colyseus.sdk@970cbca8b8/Runtime/Colyseus/Room/ColyseusRoom.cs:449)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at <7ec8e29954a6455daa48484a381ec418>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <9abcb063327f4befb6ae8615dcf16958>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <9abcb063327f4befb6ae8615dcf16958>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <9abcb063327f4befb6ae8615dcf16958>:0)

It seems server send a wrong length byte stream in setting room state: else if (code == ColyseusProtocol.ROOM_STATE)
{
Console.WriteLine(bytes);
SetState(bytes, 1);
}`

my unity version is 2022.3.15f1c1
sdk version is 0.16.13
server dependencies:
"devDependencies": {
"@colyseus/loadtest": "^0.16.0",
"@colyseus/testing": "^0.16.0",
"@types/express": "^4.17.1",
"@types/mocha": "^10.0.1",
"mocha": "^10.2.0",
"rimraf": "^5.0.0",
"tsx": "^4.10.2",
"typescript": "^5.0.4"
},
"dependencies": {
"@colyseus/monitor": "^0.16.0",
"@colyseus/playground": "^0.16.0",
"@colyseus/tools": "^0.16.0",
"colyseus": "^0.16.0",
"express": "^4.18.2"
}
the server code is that example server
I haven`t modify any code yet
I think the most possible reason is verson different issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions