Photon events are causing exceptions

Options
This is a bit of a strange post because I'm not 100% sure this is causing the real issue I'm having, but I'm at least 90% sure it's an issue for someone. My problem is when joining a room, in NetworkingPeer.cs, in the OnEvent method it'll want to broadcast an OnJoinedRoom event to all GameObjects. However, it does this by getting a list of GameObjects, iterating through them and trying to call the method using SendMessage. This is done in SendMonoMessage on line 1933 of NetworkingPeer.cs.

Sounds OK, but the real issue is when one of your GameObjects has an OnJoinedRoom method that destroys another GameObject that the loop in SendMonoMessage hasn't visited yet, it will throw a MissingReferenceException and (I presume) stop iterating through this list of GameObjects. Some OnJoinedRoom (or similar) methods won't be called like they should be.

I solved this temporarily by modifying SendMonoMessage to check if the gameobject is null before trying to use SendMessage on it. The modified method is here.

public static void SendMonoMessage(PhotonNetworkingMessage methodString, params object[] parameters) {
HashSet objectsToCall;
if(PhotonNetwork.SendMonoMessageTargets != null) {
objectsToCall = PhotonNetwork.SendMonoMessageTargets;
} else {
objectsToCall = PhotonNetwork.FindGameObjectsWithComponent(PhotonNetwork.SendMonoMessageTargetType);
}

string methodName = methodString.ToString();
object callParameter = (parameters != null && parameters.Length == 1)?parameters[0]:parameters;
foreach(GameObject gameObject in objectsToCall) {
if(gameObject != null) {
gameObject.SendMessage(methodName, callParameter, SendMessageOptions.DontRequireReceiver);
}
}
}

Comments

  • jeanfabre
    Options
    Hi,

    Thanks for reporting, this fix will make it in the next update on the Assets store.

    Bye,

    Jean