XML Handler null reference exception onLeaveRoom

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

Posts: 11
Joined: 02 Apr 2009, 04:29

XML Handler null reference exception onLeaveRoom

Postby shaitaaan » 14 Apr 2009, 08:44


We are getting the following error when a user leaves a room.

Code: Select all

=========== SMARTFOX : XML Handler null reference exception System.NullReferenceException: Object reference not set to an instance of an object
 at SmartFoxClientAPI.Handlers.SysHandler.HandleUserLeaveRoom (System.Xml.XmlNode xml) [0x00000]
 at SmartFoxClientAPI.Handlers.SysHandler.HandleMessage (System.Object msgObj, System.String type) [0x00000]
 at SmartFoxClientAPI.SmartFoxClient.XmlReceived (System.String msg) [0x00000]  ===========
SF_Server:SFUnityLog(Object) (at Assets/Server/SF_Server.cs:189)
SF_Server:OnDebugMessage(String) (at Assets/Server/SF_Server.cs:866)

What are we doing wrong here?

Thanks in advance.
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 15 Apr 2009, 04:55


Seems like "same same" like last time (hard to say without the XML to look at). The code has this:

Code: Select all

         int userId = XmlUtil.GetInt(xml, "body/user/@id");
         int roomId = XmlUtil.GetInt(xml, "body/@r");

         // Get room
         Room theRoom = sfs.GetRoom(roomId);
         // Get user name
         string uName = theRoom.GetUser(userId).GetName();

Those are the 2 only potential sources for the NRE that gets thrown.

So either the roomlist is not up to date on the client with the room that you try to leave - or the user list never got updated on the client for that room.

I cannot from the error see which it is - the room or the user object - that is a null.

User list only gets updated when joining a specific room - so if you have special extension code trying to mimic the build in functionality, then you need to make sure that the clients get the same data as "normally".

The upcoming 1.2 has checks for both these objects - so if you want (PM me) I can send you a development build that should print the real cause to the error log.

The 1.2 will not solve your problem - but it will help you find the issue (as well as not crashing the API)


Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 2 guests