Page 1 of 1

XML Handler null reference exception onLeaveRoom

Posted: 14 Apr 2009, 08:44
by shaitaaan

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.

Posted: 15 Apr 2009, 04:55
by ThomasLund

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)