Page 1 of 1

iOS Serialization / Deserialization anomaly

Posted: 12 Mar 2014, 15:03
by alienwoods
Hi,

We use Unity 4.3.2 and SmartFox SX 2.8.2. Unity code is C#, and platform is iOS.

We use a custom extension which has some problems already in topic: http://forums.smartfoxserver.com/viewto ... 8&start=15.

Our newest issue is that the SFSObject that send via SmartFox.Send() command as an extension request, has cutted out the cmd paramter from the request tcp package after the first turn around. This means the request executes for the first time, we get a correct response from the server, but for the further serialization tries fail. To try this we created a SerializableSFSType object:

Code: Select all

using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Protocol.Serialization;

public class MySFS : SerializableSFSType {
	public string name;

	public MySFS (string s){
		name = s;
		}
}
We tried to serialize this before and after the first extension response processing, and there was a difference already :

Code: Select all

DefaultSFSDataSerializer serializer = DefaultSFSDataSerializer.Instance;
		DefaultSFSDataSerializer.RunningAssembly = Assembly.GetExecutingAssembly();
		ISFSObject obj = serializer.Cs2Sfs(new MySFS("sanyi"));
		Debug.LogWarning ("serialized obj: " + obj.GetHexDump ());

And there was a difference between the first time and the second time of the serialized TCP packages:

first time pocket log with returning packet data:

Code: Select all

0000  80 00 46 12 00 03 00 01 63 02 01 00 01 61 03 00   ..F.....c....a..
0010  0d 00 01 70 12 00 03 00 01 63 08 00 02 71 74 00   ...p.....c...qt.
0020  01 72 04 00 00 00 01 00 01 70 12 00 03 00 01 69   .r.......p.....i
0030  04 00 00 00 01 00 01 72 04 00 00 00 01 00 01 64   .......r.......d
0040  05 00 00 00 00 00 00 00 01                        .........
    Data: 800046120003000163020100016103000d00017012000300...
second time, the cmd part "qt" is missing :

Code: Select all

0000  80 00 3e 12 00 03 00 01 63 02 01 00 01 61 03 00   ..>.....c....a..
0010  0d 00 01 70 12 00 02 00 01 72 04 00 00 00 01 00   ...p.....r......
0020  01 70 12 00 03 00 01 69 04 00 00 00 01 00 01 72   .p.....i.......r
0030  04 00 00 00 01 00 01 64 05 00 00 00 00 00 00 00   .......d........
0040  01                                                .
    Data: 80003e120003000163020100016103000d00017012000200...
How could we reinitialize the serializer from C# code from the Unity project to make it works again correctly?

Is there any exception handling where we can check the serialization issues?

Re: iOS Serialization / Deserialization anomaly

Posted: 12 Mar 2014, 15:25
by Lapo
Here is the thing. I would probably recommend not to use serializable classes if you intend to port the code to iOS via Unity Exporter.

It is my impression that the Exporter has problems with detecting native C# types once they are converted by the Exporter into ARM native code. As I explained in the other post Unity act as black box so we can't predict what's going on during the compilation to iOS.

In order to remain on the safe side I would avoid using serializable classes because they require runtime type checking and reflection. This is quite a tricky aspect to be implemented correctly and I can imagine that it could fail when compiled in iOS from Unity.
How could we reinitialize the serializer from C# code from the Unity project to make it works again correctly?
I have no idea. There is nothing to re-initialize, to be honest.
Is there any exception handling where we can check the serialization issues?
Serialization issues should never ever happen if you are using our API.
Also this kind of exception would be unrecoverable, so there's not much you could be able to do once you catch it.

thanks

Re: iOS Serialization / Deserialization anomaly

Posted: 12 Mar 2014, 15:31
by Lapo
NOTE: Moved the topic under Unity / C# Section. Even though the subject is iOS exports, the API in discussion is C#.

Re: iOS Serialization / Deserialization anomaly

Posted: 13 Mar 2014, 10:21
by alienwoods
Hi,

We found the issue:

In our OnExtensionResponse(BaseEvent e) function we tried to Debug.Log ("e.Params " + e.Params ["params"]) . This messed up the further serialization and the Smarfox server sent us a lot of Missing CMD message.

After we commented out this Debug.Log request, there was no problem with the missing cmd, so the serilization worked as we expected, all times!

Re: iOS Serialization / Deserialization anomaly

Posted: 13 Mar 2014, 11:38
by Lapo
I am glad you found the problem, but I find this to be pretty bizarre :shock:
How a simple Debug.Log could interfere or break the serialization is beyond me...

Re: iOS Serialization / Deserialization anomaly

Posted: 13 Mar 2014, 11:50
by Lapo
I've tried to add that line of code in the Extension response handler but nothing bad happens.
This again was tested in the iPad emulator but I would expect the results to be consistent. Very puzzling. :?