Weird error that I only see when running on Android

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

JuliusBtesh
Posts: 58
Joined: 30 Sep 2014, 17:08

Weird error that I only see when running on Android

Postby JuliusBtesh » 15 Dec 2014, 15:39

I have been getting this error when sending an extension request from an Android device to the server. But it doesn't seem to always happen. It only happens randomly so I'm not sure what could be causing this issue.

This is the error I received;

Code: Select all

I/Unity   ( 7355): InvalidCastException: Cannot cast from source type to destination type.
I/Unity   ( 7355):   at Sfs2X.Protocol.Serialization.DefaultSFSDataSerializer.EncodeObject (Sfs2X.Util.ByteArray buffer, Int32 typeId, System.Object data) [0x00000] in <filename unknown>:0
I/Unity   ( 7355):   at Sfs2X.Protocol.Serialization.DefaultSFSDataSerializer.Obj2bin (ISFSObject obj, Sfs2X.Util.ByteArray buffer) [0x00000] in <filename unknown>:0
I/Unity   ( 7355):   at Sfs2X.Protocol.Serialization.DefaultSFSDataSerializer.Object2Binary (ISFSObject obj) [0x00000] in <filename unknown>:0
I/Unity   ( 7355):   at Sfs2X.Entities.Data.SFSObject.ToBinary () [0x00000] in <filename unknown>:0
I/Unity   ( 7355):   at Sfs2X.Entities.Data.SFSObject.GetHexDump () [0x00000] in <filename unknown>:0
I/Unity   ( 7355):   at Sfs2X.Core.SFSProtocolCodec.OnPacketWrite (IMessage message) [0x00000] in <filename unknown>:0
I/Unity   ( 7355):   at Sfs2X.Bitswarm.BitSwarmClient.Send (IMessage message) [0x00000] in <filename unknown>:0
I/Unity   ( 7355):   at Sfs2X.SmartFox.Send (IRequest request) [0x00000] in <filename unknown>:0
I/Unity   ( 7355):   at GameManager.OnReturnToGames () [0x00000] in <filename unknown>


And this is the function that's being called

Code: Select all

if (smartFox.IsConnected) {
         smartFox.Send(new ExtensionRequest("OnLeavingRoom", new SFSObject(), smartFox.LastJoinedRoom));
         smartFox.Send(new LeaveRoomRequest());
         LeaveRoom();
      }


Thanks!
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Weird error that I only see when running on Android

Postby Lapo » 15 Dec 2014, 16:52

It's probably not the best idea to send those two requests one after the other, especially because one if for the Extension Controller and the other for the System Controller (the LeaveRoomReq)

Since they will be handled by two different controller (managed by different threads) if you send them at the same time they might end up in reverse order.

You have two ways of fixing this:

1- wait for the Extension response and then send the LeaveRoom
2- incorporate the LeavRoomRequest on the server side, in your Extension call, so that you no longer need to invoke it from client side.

Also, I don't know what your LeaveRoom() method does but I would wait to call it until the server request has completed.

I can't say if this will fix the problem, maybe not, but in general that's the best way to handle this sort of "multi calls"

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
JuliusBtesh
Posts: 58
Joined: 30 Sep 2014, 17:08

Re: Weird error that I only see when running on Android

Postby JuliusBtesh » 15 Dec 2014, 17:28

Thanks will give it a try

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 11 guests