Sometimes I got this exception on Unity client side, when I use this function ; (It is so hard to reproduce !)
bool isSpectator = smartfox.MySelf.IsSpectator ;
NullReferenceException : Object reference not set to an instance of an object
at Sfs2X.Entities.SFSUser.GetPlayerId(Sfs2X.Entities.SFSUser)
at Sfs2X.Entities.SFSUser.get_PlayerId(Sfs2X.Entities.SFSUser)
at Sfs2X.Entities.SFSUser.get_IsPlayer(Sfs2X.Entities.SFSUser)
at Sfs2X.Entities.SFSUser.get_IsSpectator(Sfs2X.Entities.SFSUser)
Unity v : 5.5.0f3
Smartfox backend v : 2.12.0
Smartfox client v : 1.6.6
Unity MySelf.IsSpectator Exception
-
- Posts: 30
- Joined: 30 Apr 2016, 07:23
- Location: Turkey
Re: Unity MySelf.IsSpectator Exception
Hi,
this is likely due to incorrect Room logic.
You must check to be at least joined in a Room if you want to query the user's status in that Room (e.g. is the player a spectator etc...)
If your client uses one room at a time (no multi-room) simply add this check before reading the isSpectator property:
This is because isSpectator and isPlayer assume you're at least joined in a Room (the one referenced by lastJoinedRoom property) and if a join error occurred or the player is simply not connected to any Room, this will fail.
Hope it helps
this is likely due to incorrect Room logic.
You must check to be at least joined in a Room if you want to query the user's status in that Room (e.g. is the player a spectator etc...)
If your client uses one room at a time (no multi-room) simply add this check before reading the isSpectator property:
Code: Select all
if (sfs.LastJoinedRoom != null)
{
// check user status here...
}
This is because isSpectator and isPlayer assume you're at least joined in a Room (the one referenced by lastJoinedRoom property) and if a join error occurred or the player is simply not connected to any Room, this will fail.
Hope it helps
-
- Posts: 30
- Joined: 30 Apr 2016, 07:23
- Location: Turkey
Re: Unity MySelf.IsSpectator Exception
After SFSEvent.ROOM_JOIN event is fire from smartfox , I got this exception. lastJoinedRoom can not be null ( Again it is so hard to reproduce)
I saw this exception on crashlytics.
I saw this exception on crashlytics.
Re: Unity MySelf.IsSpectator Exception
Since the error appears only in rare cases I would recommend to revise your code and make sure that join errors are handled correctly, otherwise the game logic will proceed to execute code that fails because your application is in the wrong state.
Another option is that the user has left the Room, but not yet joined another one. In any case lastJoinedRoom will be null.
We have taken a closer look at the API's code and there's no other way to cause the NRE other than the lastJoinedRoom being Null.
Another option is that the user has left the Room, but not yet joined another one. In any case lastJoinedRoom will be null.
We have taken a closer look at the API's code and there's no other way to cause the NRE other than the lastJoinedRoom being Null.
Who is online
Users browsing this forum: No registered users and 36 guests