Page 1 of 1

Weird error that I only see when running on Android

Posted: 15 Dec 2014, 15:39
by JuliusBtesh
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!

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

Posted: 15 Dec 2014, 16:52
by Lapo
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

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

Posted: 15 Dec 2014, 17:28
by JuliusBtesh
Thanks will give it a try