Null user error

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
moccha
Posts: 112
Joined: 13 Feb 2014, 16:09

Null user error

Postby moccha » 26 Jul 2015, 02:27

Sorry to bother you again so soon, Lapo. After about one in every four tries, when I connect as a guest or user in one client, the other client freezes and gives this error:

Code: Select all

Cannot access a property or method of a null object reference.
   at com.smartfoxserver.v2.entities.managers::SFSUserManager/addUser()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/managers/SFSUserManager.as:78]
   at com.smartfoxserver.v2.entities::SFSRoom/addUser()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/SFSRoom.as:439]
   at com.smartfoxserver.v2.controllers::SystemController/fnSetUserPosition()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:1457]
   at com.smartfoxserver.v2.controllers::SystemController/handleMessage()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:137]
   at com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:150]
   at com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:54]
   at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:254]
   at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:113]
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:474]


Once I ignore the bug, the other player doesn't show up. Something is causing a null exception in the code and the user isn't added to the game. This happens in both MMO rooms and game rooms. I recently updated to SFS2X 2.10 and I updated my AS3 API.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Null user error

Postby Lapo » 26 Jul 2015, 18:50

Can you please describe all of the steps that lead to the error?
Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
moccha
Posts: 112
Joined: 13 Feb 2014, 16:09

Re: Null user error

Postby moccha » 27 Jul 2015, 02:23

Sure thing, Lapo. In this scenario there is player1 and player2.

1.) Player1 connects to server as Guest, is logged in to an MMO room.
2.) Player2 connects to server with Username, is logged in to an MMO room.
3.) Player2 sees the posted error message in debugger, Player1 doesn't appear. Player1 sees Player2 correctly.

It can happen as easily as that. Rarely both players load correctly on login. I've also had this occur when both players login as guests, but inconsistently.

What happens in the source at the described error line?I don't think I've made any changes that might have caused this error, but maybe I'm feeding in bad data somewhere? After I continue and dismiss the error, it just keeps writing this message to debugger every frame:

Code: Select all

RangeError: Error #2006: The supplied index is out of bounds.
   at flash.utils::ByteArray/writeBytes()
   at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:242]
   at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:113]
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:474]
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Null user error

Postby Lapo » 27 Jul 2015, 06:21

I have no idea how to reproduce this issue. We have built complete games and demos with the MMORoom and have never seen anything like that.
Also we don't have other reports of similar issues. I suspect there is something else going on...

Can you send us a simplified client that reproduces the problem?

You can zip the necessary files (Extension included, if needed) and send it to our support@... email with a reference to this thread.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
moccha
Posts: 112
Joined: 13 Feb 2014, 16:09

Re: Null user error

Postby moccha » 27 Jul 2015, 17:36

I'm going to keep testing various things I may have changed to see if I can resolve this, but I was wondering: what happens in the SFS source at this line?

Code: Select all

com.smartfoxserver.v2.entities.managers::SFSUserManager/addUser()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/managers/SFSUserManager.as:78]


What does the SFSUserManager try to do on line 78?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Null user error

Postby Lapo » 27 Jul 2015, 18:58

The line of code in the error is not even relative to the method stated in the stack trace (addUser).
Are you sure you're using the latest API available? If not I'd recommend upgrading. Probably it won't solve the issue but at least it might improve the error reporting:
http://smartfoxserver.com/download/sfs2x#p=client

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
moccha
Posts: 112
Joined: 13 Feb 2014, 16:09

Re: Null user error

Postby moccha » 27 Jul 2015, 20:11

I've triple checked that I'm using the latest version of the API, confirming the version 1.6.0 via a trace. I tried viewing a data dump of a time when the game broke and I noticed something. In this code there is a logged in user "q1q1q1" and a guest user. The game broke on "SetUserPosition", and I noticed the packet it broke on is larger than normal and looks to have double the normal amount of user data in the packet. Here's a normal version of a "SetUserPosition" packet. Note the binary size.

Code: Select all

SFS2X|INFO] Data Read: Binary Size: 208
80 00 CD 12 00 03 00 01 61 03 00 1E 00 01 63 02    ........a.....c.
00 00 01 70 12 00 02 00 01 72 04 00 00 00 00 00    ...p.....r......
01 70 11 00 01 11 00 06 04 00 00 00 3F 08 00 08    .p..........?...
47 75 65 73 74 23 36 33 03 00 00 03 00 00 11 00    Guest#63........
09 11 00 03 08 00 01 72 02 02 04 00 00 00 00 11    .......r........
00 03 08 00 01 67 02 01 01 00 11 00 03 08 00 02    .....g..........
6E 63 02 02 04 00 00 00 00 11 00 03 08 00 03 77    nc.............w
69 6E 02 02 04 00 00 00 00 11 00 03 08 00 01 74    in.............t
02 02 04 00 00 00 00 11 00 03 08 00 01 66 02 02    .............f..
04 FF FF FF FF 11 00 03 08 00 02 69 64 02 02 04    ...........id...
00 00 00 00 11 00 03 08 00 04 63 6C 75 62 02 04    ..........club..
08 00 01 6E 11 00 03 08 00 02 65 78 02 04 08 00    ...n......ex....
00 0C 00 03 00 00 00 6E 00 00 00 82 00 00 00 00    .......n........

[SFS2X|INFO] SetUserPosition, { Message id: 30 }
{ Dump: }

   (int) r: 0
   (sfs_array) p:
      (sfs_array)
         (int) 63
         (utf_string) Guest#63
         (short) 0
         (short) 0
         (sfs_array)
            (sfs_array)
               (utf_string) r
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) g
               (byte) 1
               (bool) false
            
            (sfs_array)
               (utf_string) nc
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) win
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) t
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) f
               (byte) 2
               (int) -1
            
            (sfs_array)
               (utf_string) id
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) club
               (byte) 4
               (utf_string) n
            
            (sfs_array)
               (utf_string) ex
               (byte) 4
               (utf_string)
            
         
         (int_array) [110,130,0]


And then here's the SetUserPosition packet that broke the SFS instance, plus a few packets before the error. It's obvious that the packet is incorrect and it's trying to read in something too big.

Code: Select all

[SFS2X|INFO] Data written: Binary Size: 90
12 00 03 00 01 63 02 01 00 01 61 03 00 0D 00 01    .....c....a.....
70 12 00 03 00 01 63 08 00 01 64 00 01 72 04 FF    p.....c...d..r..
FF FF FF 00 01 70 12 00 05 00 02 72 6D 08 00 05    .....p.....rm...
4C 6F 62 62 79 00 01 78 04 00 00 00 A5 00 02 69    Lobby..x.......i
64 08 00 06 71 31 71 31 71 31 00 01 66 04 00 00    d...q1q1q1..f...
00 10 00 01 79 04 00 00 00 82                      ....y.....     

[SFS2X|INFO] Data Read: Binary Size: 75
80 00 48 12 00 03 00 01 61 03 00 0D 00 01 63 02    ..H.....a.....c.
01 00 01 70 12 00 02 00 01 63 08 00 01 6D 00 01    ...p.....c...m..
70 12 00 04 00 01 66 04 00 00 00 10 00 04 75 73    p.....f.......us
65 72 08 00 06 71 31 71 31 71 31 00 01 78 04 00    er...q1q1q1..x..
00 00 A5 00 01 79 04 00 00 00 82                   .....y.....     

[SFS2X|INFO] { Message id: 13 }
{ Dump: }

   (utf_string) c: m
   (sfs_object) p:
      (int) x: 165
      (int) f: 16
      (utf_string) user: q1q1q1
      (int) y: 130
   

[SFS2X|INFO] Data Read: Binary Size: 38
80 00 23 12 00 03 00 01 61 03 03 E9 00 01 63 02    ..#.....a.....c.
00 00 01 70 12 00 02 00 01 72 04 00 00 00 00 00    ...p.....r......
02 75 63 03 00 02                                  .uc...         

[SFS2X|INFO] UserCountChange, { Message id: 1001 }
{ Dump: }

   (int) r: 0
   (short) uc: 2

[SFS2X|INFO] Data Read: Binary Size: 379
80 01 78 12 00 03 00 01 61 03 00 1E 00 01 63 02    ..x.....a.....c.
00 00 01 70 12 00 02 00 01 72 04 00 00 00 00 00    ...p.....r......
01 70 11 00 02 11 00 06 04 00 00 00 40 08 00 08    .p..........@...
47 75 65 73 74 23 36 34 03 00 00 03 00 00 11 00    Guest#64........
09 11 00 03 08 00 01 72 02 02 04 00 00 00 00 11    .......r........
00 03 08 00 01 67 02 01 01 00 11 00 03 08 00 02    .....g..........
6E 63 02 02 04 00 00 00 00 11 00 03 08 00 03 77    nc.............w
69 6E 02 02 04 00 00 00 00 11 00 03 08 00 01 74    in.............t
02 02 04 00 00 00 00 11 00 03 08 00 01 66 02 02    .............f..
04 FF FF FF FF 11 00 03 08 00 02 69 64 02 02 04    ...........id...
00 00 00 00 11 00 03 08 00 04 63 6C 75 62 02 04    ..........club..
08 00 01 6E 11 00 03 08 00 02 65 78 02 04 08 00    ...n......ex....
00 0C 00 03 00 00 00 6E 00 00 00 82 00 00 00 00    .......n........
11 00 06 04 00 00 00 40 08 00 08 47 75 65 73 74    .......@...Guest
23 36 34 03 00 00 03 00 00 11 00 09 11 00 03 08    #64.............
00 01 72 02 02 04 00 00 00 00 11 00 03 08 00 01    ..r.............
67 02 01 01 00 11 00 03 08 00 02 6E 63 02 02 04    g..........nc...
00 00 00 00 11 00 03 08 00 03 77 69 6E 02 02 04    ..........win...
00 00 00 00 11 00 03 08 00 01 74 02 02 04 00 00    ..........t.....
00 00 11 00 03 08 00 01 66 02 02 04 FF FF FF FF    ........f.......
11 00 03 08 00 02 69 64 02 02 04 00 00 00 00 11    ......id........
00 03 08 00 04 63 6C 75 62 02 04 08 00 01 6E 11    .....club.....n.
00 03 08 00 02 65 78 02 04 08 00 00 0C 00 03 00    .....ex.........
00 00 6E 00 00 00 82 00 00 00 00                   ..n........     

[SFS2X|INFO] SetUserPosition, { Message id: 30 }
{ Dump: }

   (int) r: 0
   (sfs_array) p:
      (sfs_array)
         (int) 64
         (utf_string) Guest#64
         (short) 0
         (short) 0
         (sfs_array)
            (sfs_array)
               (utf_string) r
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) g
               (byte) 1
               (bool) false
            
            (sfs_array)
               (utf_string) nc
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) win
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) t
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) f
               (byte) 2
               (int) -1
            
            (sfs_array)
               (utf_string) id
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) club
               (byte) 4
               (utf_string) n
            
            (sfs_array)
               (utf_string) ex
               (byte) 4
               (utf_string)
            
         
         (int_array) [110,130,0]
      
      (sfs_array)
         (int) 64
         (utf_string) Guest#64
         (short) 0
         (short) 0
         (sfs_array)
            (sfs_array)
               (utf_string) r
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) g
               (byte) 1
               (bool) false
            
            (sfs_array)
               (utf_string) nc
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) win
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) t
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) f
               (byte) 2
               (int) -1
            
            (sfs_array)
               (utf_string) id
               (byte) 2
               (int) 0
            
            (sfs_array)
               (utf_string) club
               (byte) 4
               (utf_string) n
            
            (sfs_array)
               (utf_string) ex
               (byte) 4
               (utf_string)
            
         
         (int_array) [110,130,0]
      
   

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at com.smartfoxserver.v2.entities.managers::SFSUserManager/addUser()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/managers/SFSUserManager.as:78]
   at com.smartfoxserver.v2.entities::SFSRoom/addUser()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/entities/SFSRoom.as:439]
   at com.smartfoxserver.v2.controllers::SystemController/fnSetUserPosition()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:1457]
   at com.smartfoxserver.v2.controllers::SystemController/handleMessage()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:137]
   at com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:150]
   at com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:54]
   at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:254]
   at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:113]
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:474]


Is there a reason that the packet almost looks to be duplicated in size? It looks abnormal, possibly even malformed? Again, this problem is not consistent. Sometimes it happens on the first try, other times it takes a few tries. I haven't had this issue prior to update. No error shows up in the server log either.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Null user error

Postby Lapo » 28 Jul 2015, 08:00

The "suspicious" packet contains twice the user "Guest 64", which presumably causes the subsequent error.

Are you maybe running a personal firewall (other than the system's one) on a Windows machine? I ask because it's not unusual that some software firewalls cause all sorts of strange packet alterations. It has happened before.

Windows firewall is usually fine. Others not much. If you're running something else try shutting the FW down. Sometimes this is not even sufficient and an uninstall is necessary :(

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
moccha
Posts: 112
Joined: 13 Feb 2014, 16:09

Re: Null user error

Postby moccha » 28 Jul 2015, 17:10

I am running this instance on OSX 10.10.3. I do have a firewall (LittleSnitch), but even after turning it off I was able to reproduce the problem. Initially I was excited as I could not reproduce the error after about 10 tries, but shortly after a rapid test cycle I again received a bad packet. I am performing the test by logging in in one client, and just repeatedly logging in and out in another client. This test is being done in an mmo room. Both clients send a movement update and a SetUserPositionRequest every 200 ms (setuser only if in MMO room though).

After downgrading back to 2.9.0, I was still able to reproduce the problem. However, after switching back to the old Flex API SWC (1.2.0), I was not able to reproduce the problem after 70+ tries. I tried upgrading SFS to 2.10 again and I was still not able to reproduce the problem. I am almost positive that somethings definitely being handled differently in the 1.6.0 SWC and its causing a packet error.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Null user error

Postby Lapo » 28 Jul 2015, 18:46

The old SFS API (1.2) do not support MMORoom, so that doesn't count. :(
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Null user error

Postby Lapo » 28 Jul 2015, 18:50

Also how could you test the same situation if the old API don't even have the SetUserPosition request?
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
moccha
Posts: 112
Joined: 13 Feb 2014, 16:09

Re: Null user error

Postby moccha » 28 Jul 2015, 19:13

Version 1.2.0 has MMORoom functionality. You can confirm here: http://www.smartfoxserver.com/download/ ... PI_AS3.txt

I actually haven't tested with 1.2.5, if you know where I can obtain that SWC please let me know. It looks like a lot changed specifically with MMO rooms in that release. I also confirmed I'm not sending floats in case that was causing an error with the new "useFloatCoordinates" param.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Null user error

Postby Lapo » 29 Jul 2015, 09:20

moccha wrote:Version 1.2.0 has MMORoom functionality. You can confirm here: http://www.smartfoxserver.com/download/ ... PI_AS3.txt

I actually haven't tested with 1.2.5, if you know where I can obtain that SWC please let me know. It looks like a lot changed specifically with MMO rooms in that release. I also confirmed I'm not sending floats in case that was causing an error with the new "useFloatCoordinates" param.

Sorry I stand corrected, you're right. Version 1.2.0 was the first AS3 release supporting MMO, I got confused with Unity.

In any case I don't think this is the solution to the problem. I have taken our SimpleMMOWorld example, recompiled it with the latest 1.6.0 API and run 15 tests without encountering a single issue.

Maybe you could try the same and if you don't see any problem too we should see what is different in your code. Once again, it would be best for us to see a proof-of-concept that reproduces the problem, even if it doesn't do it every time, it would be a start.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
moccha
Posts: 112
Joined: 13 Feb 2014, 16:09

Re: Null user error

Postby moccha » 29 Jul 2015, 18:20

I believe I found the issue. As I stated earlier, my game was ending both a movement update and also a SetUserPos command every 200 ms.I only need to send one SetUserPos obviously as i join room, so this was incorrect. for whatever reason, the when sending both of the commands at the same time it can cause an error with the new api. I don't know what would cause the packets to splice together, but it was happening.

Thanks for all your help lapo. hope this helps someone in the future
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Null user error

Postby Lapo » 29 Jul 2015, 21:26

I see.
Sending two different requests at the same time can cause out-of-order execution because two different threads will run in parallel and the code that takes less to execute will finish first. In the case of JoinRoom and SetUserPosition, they definitely need to be executed serially.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 57 guests