Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

User avatar
arodrigo
Posts: 24
Joined: 22 Jul 2011, 10:03
Location: Spain
Contact:

Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Postby arodrigo » 08 Aug 2017, 11:56

Hi!

We are migrating to the new javascript client, and all works perfect except for this error when a player of the room have a var with a long greater than the supported by the number like 10201670634517191.

Code: Select all

Uncaught Error: Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1) <= value <= +(2^53 - 1)
    at SFSTypeError.SFSError (VM2126 SFS2X_API_JS.js:formatted:5539)
    at new SFSTypeError (VM2126 SFS2X_API_JS.js:formatted:5569)
    at Object.validate (VM2126 SFS2X_API_JS.js:formatted:5981)
    at SFSArray.add (VM2126 SFS2X_API_JS.js:formatted:6476)
    at SFSDataSerializer.decodeSFSArray (VM2126 SFS2X_API_JS.js:formatted:5095)
    at SFSDataSerializer.decodeObject (VM2126 SFS2X_API_JS.js:formatted:5147)
    at SFSDataSerializer.decodeSFSArray (VM2126 SFS2X_API_JS.js:formatted:5093)
    at SFSDataSerializer.decodeObject (VM2126 SFS2X_API_JS.js:formatted:5147)
    at SFSDataSerializer.decodeSFSArray (VM2126 SFS2X_API_JS.js:formatted:5093)
    at SFSDataSerializer.decodeObject (VM2126 SFS2X_API_JS.js:formatted:5147)
SFSError @ VM2126 SFS2X_API_JS.js:formatted:5539
SFSTypeError @ VM2126 SFS2X_API_JS.js:formatted:5569
validate @ VM2126 SFS2X_API_JS.js:formatted:5981
add @ VM2126 SFS2X_API_JS.js:formatted:6476
decodeSFSArray @ VM2126 SFS2X_API_JS.js:formatted:5095
decodeObject @ VM2126 SFS2X_API_JS.js:formatted:5147
decodeSFSArray @ VM2126 SFS2X_API_JS.js:formatted:5093
decodeObject @ VM2126 SFS2X_API_JS.js:formatted:5147
decodeSFSArray @ VM2126 SFS2X_API_JS.js:formatted:5093
decodeObject @ VM2126 SFS2X_API_JS.js:formatted:5147
decodeSFSArray @ VM2126 SFS2X_API_JS.js:formatted:5093
decodeObject @ VM2126 SFS2X_API_JS.js:formatted:5147
decodeSFSArray @ VM2126 SFS2X_API_JS.js:formatted:5093
decodeObject @ VM2126 SFS2X_API_JS.js:formatted:5147
decodeSFSObject @ VM2126 SFS2X_API_JS.js:formatted:5070
decodeObject @ VM2126 SFS2X_API_JS.js:formatted:5151
decodeSFSObject @ VM2126 SFS2X_API_JS.js:formatted:5070
binary2object @ VM2126 SFS2X_API_JS.js:formatted:5044
newFromBinaryData @ VM2126 SFS2X_API_JS.js:formatted:6330
onPacketRead @ VM2126 SFS2X_API_JS.js:formatted:5791
_onSocketData @ VM2126 SFS2X_API_JS.js:formatted:5716


When this occurs the room event SFS2X.SFSEvent.ROOM_JOIN never arrives. We know that the long is a problem on Javascript but if will be appreciated if instead of the exception a warning is throw.

Let me know if do you need more information.

Thanks in advance.

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

Re: Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Postby Lapo » 08 Aug 2017, 14:44

Hi,
well, as the error says there's a limit in the size of long integers in JS which is 2^53.

Normally you would expect long integers to be 64 bit long (2^64) but JS is limited because it represents longs as doubles.
If you want all the "dirty" details see here:
https://stackoverflow.com/questions/173 ... ng-integer

Bottom line, it's a limitation of the javascript language.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
arodrigo
Posts: 24
Joined: 22 Jul 2011, 10:03
Location: Spain
Contact:

Re: Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Postby arodrigo » 08 Aug 2017, 15:39

Hi Lapo,

Yes we know and we understand the limitation. I think i have not explained myself correctly.

With the previous implementation of the javascript with the json protocol this wasn't a problem because even if the long exceeds the number of javascript it was converted to another invalid value and all the events were sent correctly.

Now with the new javascript implementation using the binary protocol. If this happens, an exception is throw and avoid that events like SFS2X.SFSEvent.ROOM_JOIN will be send.

If we want to use the new javascript with this behavior we will be forced to review all the code of the server side that was working with all our other clients like flash our unity.

To avoid this we suggest if you may change this behavior and send log with a warning in the console and put a NaN or whatever on the variable (can be a configuration). With that we could progressively adapt the variables without affect to the old clients.

Thank you very much for your time.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Postby Lapo » 09 Aug 2017, 07:08

Hi,
thanks for the clarification. It makes sense.
We'll investigate the issue and get back to you.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Postby Bax » 18 Aug 2017, 09:33

What I don't understand is how a wrong number is acceptable in your code.
If the number is meaningful, then you would end up having a different value on different clients (flat/unity vs html5).
If the number is not meaningful, then you should change your code generating it.
Changing the error to warning wouldn't solve the issue but will make the issue more difficult to spot in other scenarios, don't you think?
Paolo Bax
The SmartFoxServer Team
User avatar
arodrigo
Posts: 24
Joined: 22 Jul 2011, 10:03
Location: Spain
Contact:

Re: Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Postby arodrigo » 18 Aug 2017, 12:07

This is absolutely wrong

1 Retro-compatibility

I have clients working with the log values without problem and for them this variable means something. And i don't want to change them when they are working. I have to prepare the change on the server side and then prepare a new build for all the platforms and then wait to the apple store to approve the app and then make the change on the server and then finally force the update. And this for our 12 apps.

For the javascript clients "if i need the value" I can work in some workaround, but that is my responsibility.

2 The data even if its invalid for javascript "stills valid"

The only way to accept this as an error Throw send the error on the server side when the server tries to send if. But you don't want to do that because you break the Retro-compatibility again. So, if you don't avoid that on the server way do you force me on the client now?

3 If you receive the data as byte array you can process de long number

Yep i know that you cannot use a number of javascript buy you can process de stream as an HEX.

So yes, the invalid number is not acceptable for us as you say but we don't want it we want to use the library and ignore it without have to be forced to change our server side code.

Thanks
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Postby Bax » 21 Aug 2017, 07:33

I'm curious, sorry: does that mean that you have 12 apps sharing the same Extension?

About your objection on retro-compatibility, we never stated the the new API was retro-compatible. The issue with longs is incompatible by language design, so there isn't much we can do about it. Not checking the value may lead to other issues even more difficult to spot.
This can't be checked on the server side, because there's no connection between the time the SFSObject is created and when it is sent to a client. Traversing all SFSObjects and SFSArrays before sending them to look for invalid long values before sending them to JS clients would be an overkill.

In any case we are trying to figure out how to skip the values validation when the objects are received from the server, while keeping it when developers instantiate them on the client side.
Paolo Bax
The SmartFoxServer Team
User avatar
arodrigo
Posts: 24
Joined: 22 Jul 2011, 10:03
Location: Spain
Contact:

Re: Invalid value passed; type SFSDataType.LONG requires an integer number in this range: -(2^53 - 1)

Postby arodrigo » 21 Aug 2017, 15:45

I'm curious, sorry: does that mean that you have 12 apps sharing the same Extension?

Nop!! But we have a framework for the turn games that it's used in all our apps.

In any case we are trying to figure out how to skip the values validation when the objects are received from the server, while keeping it when developers instantiate them on the client side.


Perfect thank you

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 26 guests