Page 1 of 1

Null reference error in UserList::initDataProvider()

Posted: 07 Apr 2011, 06:28
by Farbs
Hi,

The following error occurs sometimes, but not always, when we remove a UserList from the stage at the same time as a user leaves the room. Unfortunately we don't have source so I can't look up any of the entries in the stack.

Code: Select all

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at com.smartfoxserver.smartfoxbits.bits::UserList/initDataProvider()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/SmartFoxBits/Flex/Base Pack/source/src/com/smartfoxserver/smartfoxbits/bits/UserList.as:1161]
   at com.smartfoxserver.smartfoxbits.bits::UserList/onUserExitRoom()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/SmartFoxBits/Flex/Base Pack/source/src/com/smartfoxserver/smartfoxbits/bits/UserList.as:1434]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at com.smartfoxserver.v2.controllers::SystemController/fnUserExitRoom()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/controllers/SystemController.as:552]
   at com.smartfoxserver.v2.controllers::SystemController/handleMessage()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/controllers/SystemController.as:123]
   at com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:150]
   at com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:54]
   at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/core/SFSIOHandler.as:231]
   at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/core/SFSIOHandler.as:90]
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:404]

Any ideas?

Posted: 07 Apr 2011, 08:36
by Bax

Code: Select all

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at com.smartfoxserver.smartfoxbits.bits::UserList/initDataProvider()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/SmartFoxBits/Flex/Base Pack/source/src/com/smartfoxserver/smartfoxbits/bits/UserList.as:1161]

This is what line 1161 does:

Code: Select all

var userList:Object = smartFox.lastJoinedRoom.userList

I suppose lastJoinedRoom is null, because the user left the room.
What I don't understand why it just happens sometimes.
Maybe you could check the sequence of events and calls to your methods, to understand in which cases this happens.

Posted: 08 Apr 2011, 01:43
by Farbs
Cheers.

I don't seem to be able to get it to happen at all today, but on previous days it would happen sometimes, but not others, under the same circumstances. My guess is it's an order of execution problem between the display updating and the room departure message being received from the server.

I observed this problem towards the end of the day, by which time eclipse had hogged most of my system resources. I'll try running a few complete rebuilds to see if I can recreate the scenario and reproduce the bug.

Would it be possible for you to check for null on this line? I'd like to get this fixed regardless of what the cause may be.

Posted: 08 Apr 2011, 08:04
by Bax
It is not that easy to add a simple null check here, because it could interfere with the following instructions.
The strange is that usually when you leave a room, you join another one. Is this not the case of your app?

Posted: 12 Apr 2011, 03:14
by Farbs
Cheers. We currently do the following:

(1) Send an extension request from the client to the server. A request handler on the server hears this and adds the user to room B.
(2) Send a leave room request from the client to leave room A.

Is it possible that the response to leaving room A in (2) is sometimes received by the client before the response to leaving the room in (1)?

I'll try leaving the first room before joining the second one to see if that helps.

Posted: 12 Apr 2011, 03:24
by Farbs
Oh, this is interesting. By swapping steps (1) and (2) above I still saw the error, but it occurred ~80% of the time whereas before it occurred ~20% of the time.

Posted: 12 Apr 2011, 21:58
by Bax
Not sure why this happens occasionally. Anyway it seems to be related to a user not being inside a room.
We managed to fix this and it will be available in the next release of SmartFoxBits which is due... in a few minutes! 8)

Posted: 12 Apr 2011, 22:06
by Bax
Please check this post.

Posted: 12 Apr 2011, 23:26
by Farbs
Thanks bax, this is much appreciated!