Bug in SFSObject.GetByte

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

Moderators: Lapo, Bax

Post Reply
htbn_hoang
Posts: 38
Joined: 07 Oct 2013, 19:33

Bug in SFSObject.GetByte

Post by htbn_hoang »

Hi,

According to http://docs2x.smartfoxserver.com/api-docs/csharp-doc/

Code: Select all

SFSObject.GetByte
Returns the element corresponding to the specified key as a signed byte (8 bits)
But if we send -1 from server, we receive following exception
OverflowException: Value is greater than Byte.MaxValue or less than Byte.MinValue
Maybe you can add SFSObject.GetSByte to return signed byte or fix GetByte so that it works as state in the document.

BTW, can we use SetByte on server and GetInt on client (or vice versa)? Is there any problems with that?

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

Re: Bug in SFSObject.GetByte

Post by Lapo »

Hi,
I am not sure I understand the problem.
As per the documentation bytes are treated as unsigned values, therefore sending a -1 will translate to its unsigned representation which is 255.

Other than that this works just fine. I can send a -1 byte from server side and obtain a 255 in the C# client, which is correct.

The error you've posted seems to indicate something else is going on, maybe a wrong conversion from a different numerical type? Can you show us the server code used to send the data and the client code used to receive it?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
htbn_hoang
Posts: 38
Joined: 07 Oct 2013, 19:33

Re: Bug in SFSObject.GetByte

Post by htbn_hoang »

Here is code on server in Java, please check else part

Code: Select all

public ISFSObject toSFSData() {
		if (accountId != -1 || type != -1) {
			ISFSObject sfsData = new SFSObject();
			
			if (type != -1) {
				sfsData.putInt(Ban.Type, type);
				sfsData.putByte(Ban.UserGender, (byte) gender);
				sfsData.putUtfString(Ban.UserFirstNamePlus, firstNamePlus);
			} else {
				sfsData.putInt(SendMessage.UserAccountId, accountId);
				sfsData.putUtfString(SendMessage.UserFacebookId, userFacebookId);
				sfsData.putUtfString(SendMessage.UserFirstName, firstName);
				sfsData.putByte(SendMessage.UserGender, (byte) gender);
				sfsData.putInt(SendMessage.From, from);
				sfsData.putUtfString(SendMessage.Message, message);
			}
			
			return sfsData;
		}
		return null;
	}
And here is C# code

Code: Select all

chatMessage = new ChatMessage(++chatCounter);
                chatMessage.Command = param.GetInt("c");
                chatMessage.Data = new Hashtable {
                    {"name",param.GetUtfString("n")},
                    {"gender", (int)param.GetByte("g")}
                };
It seems this bug only happens in WebGL build.

Thanks
htbn_hoang
Posts: 38
Joined: 07 Oct 2013, 19:33

Re: Bug in SFSObject.GetByte

Post by htbn_hoang »

I think we should make data consistent between Java and C# by adding GetSByte.
It's strange if we set -1 on server and we receive 255 on client.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Bug in SFSObject.GetByte

Post by Lapo »

Thanks, we were able to reproduce the issue in the WebGL export.
We'll investigate and let you know.
Lapo
--
gotoAndPlay()
...addicted to flash games
htbn_hoang
Posts: 38
Joined: 07 Oct 2013, 19:33

Re: Bug in SFSObject.GetByte

Post by htbn_hoang »

Hi,

Could you please let me know when a fix will be available?

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

Re: Bug in SFSObject.GetByte

Post by Lapo »

The update is available now. See this post:
http://forums.smartfoxserver.com/viewto ... 20&t=18260

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply