PUN+ always make the editor crash

Hi,
I am using PUN+ on Unity 4.6.3 and I am having Unity Editor crash everytime I connect to a room and leave from it.

Here are the step to reproduce the errors

Play on Editor -> Connect to Photon Network -> Create Room -> Load the game -> Apply some room properties on start -> Leave the room -> Stop the Editor -> Start the Editor and the editor crash.

Currently, I have to force close the editor and re-open again to test my game.

What steps should I follow to avoid the editor crashing?
Does Leave room is not enough?
There's only one photon view in my scene and it keeps crashing.. Is that Photon Error?

I am really out of options since the error logs doesn't write to Unity Editor log file as well :(

Comments

  • Does standalone built application application work for you?
    The editor should not crash even if script fails. Did you try older editor version?
    Similar topic: viewtopic.php?f=17&t=5644&p=21578
  • Standalone application also crash as well. I've tried with 4.6.0, 4.6.1 and 4.6.2 as they all do the same behavior. Not sure about old 4.5.x version though as I don't have access to these anymore.

    It's not the same error as Unity 5.0 as I make OnApplicationQuit() function is called and Photon is disconnected once the the game is stopped from Editor. It crash once I hit play again in Editor.

    In Standalone, it just crash when I clicked the close button or call Application.Quit().

    Another bug that I found out is that the Unity Editor crash once there is an Error(Any error like instance not setup or anything) in the scene while in Photon game...

    How to Reproduce
    Create Room -> Load Scene -> instance not set error while playing the game -> Left the room or quite the game -> hit on play in Editor next time and then editor crash.

    Is there any updated PUN+ package since these errors stopping me from going into production and I have been solving it for weeks and couldn't solve it since it's a kind of Photon error.


    Another Bug
    Create Room -> Load Scene -> Send Photon Message -> Listen RPC call -> Stop the game -> Hit play in Editor and editor crash..

    photonView.RPC("OnSeatChosen", PhotonTargets.All, PhotonNetwork.player, index);

    [RPC]
    private void OnSeatChosen(PhotonPlayer sender, int seatIndex)
    {}

    So it seems to be that once I send message or applying room properties or anything related to Photon apply in the game, the editor crash on next time and it also happen on standalone builds.

    Note : All the above errors are fine on Demo scenes but it happens on my game scene and I really have no idea of why it's happening.
    Please help me fix these kind of issues so I that I can focus more on gameplay. Is that because of I am using new Unity UI? Does the new Unity has any conflicts with Photon?
  • So.. Here is the conclusion of what I've found out with the latest Unity 4.6.1, 4.6.2 or 4.6.2 on PUN+

    Bug 1 - If you use the new UI from unity 4.6.x and use any of photon related things like LeaveRoom(), Disconnect() or photonView.RPC() functions, the editor crash upon next Play... So something from Photon must conflict with 4.6.x New UI system.

    Bug 2 - If you game scene has raised any error while playing photon game, the editor crash on next play.

    ..Please Fix these erros so that I can continue working on current Multiplayer project.
  • Thanks for detailed report.
    We will fix it asap.
  • Vadim just notified me of this topic (I wasn't available before) and we will take a look.
    Did you check the latest 4.6.3p3 release by chance? It has lots of fixes that relate to compilation and exports.

    Also: Please update to the latest PUN+ v1.51 version from the Asset Store.
    It contains fixes for Unity 5 and iOS 64bit, too. Maybe something is related.
  • The same here.

    Hope it can be fixed soon.

    I am using Unity 4.6.1p1 and PUN with Unity Pro.

    Thanks!
  • You should update to the latest 4.6 version of Unity. If the editor crashes, there's a good chance this gets fixed.
    And: Send the Editor log. Maybe it shows what's happening.
  • Same problem here, I am using the latest PUN (not PUN+) and Unity 4.6.1f1

    In my case, only the last client connected to the room crashes the unity editor or the stand alone windows 64bits client.
  • mmm, Interesting. The latest Unity version is Patch 4.6.5p1, I'll give it a try tonight with the latest PUN+ and come back to post my result.

    Regards,
    Don T.
  • Hello Photon devs,

    So far so good. I did upgrade from Unity 4.5.5 and PUN+ v1.28 TO
    > Unity 4.6.5p1 and PUN+ v1.51. I had to merge 2 files from Photon that I had modified a bit, but the upgrade otherwise was smooth and simple. Thanks Tobias for the RpcSecure, I had really similar implementation, but now I did of course I kept yours :D.

    I haven't an iOS 64 bits device at my hand tonight so I could not test on that target, but on a iOS 32 bits it is working fine. In the iOS settings, I changed to the Script backend to IL2CPP and Universal, so I'm sure that I'm using this new thing :). I will definitely test on an iOS 64 bits this week-end and let you if I found any issues.

    Now, I had only one problem, which is minor, but looks like a bug in PUN and PUN+. I was getting a NullPointerException on the "for instruction" line of the following method (also in his sister method DeserializeView). I figured out that I had a PhotonView in my Scene which doesn't have any observed component, and added the code (//CODE ADDED), and it fix my problem.

    [code2=csharp]public void SerializeView( PhotonStream stream, PhotonMessageInfo info )
    {
    bool isObservedComponentsEmpty = ObservedComponents == null || (ObservedComponents.FindAll( item => item != null ).Count == 0); // CODE ADDED
    SerializeComponent( observed, stream, info );

    if (! isObservedComponentsEmpty) // CODE ADDED
    {
    for( int i = 0; i < ObservedComponents.Count; ++i )
    {
    SerializeComponent( ObservedComponents[ i ], stream, info );
    }
    }
    }[/code2]

    Cheers,
    Don T.
  • Hey guys, I just tested with the latest unity 4 (4.6.5f1) and the latest PUN (1.51) and I am having the same problem described by thetnswe...

    I can't see what is causing the crash because its not showing any errors on logs.

    Can you help me how to find what is causing this problem?
  • Ok, I just realized its related with PhotonNetwork.LoadLevel.

    I just replaced PhotonNetwork.LoadLevel for Application.LoadLevel and I am not having the crash/freeze on Unity editor or the windows client... I am still doing some more tests to be sure that this is the only source of the problem...


    Old code:
    private void CheckConnectedPlayers(){
    		LobbyUIManager.instance.UpdatePlayerConnected( PhotonNetwork.room.playerCount );
    
    		if(PhotonNetwork.room.playerCount &gt;= Constants.CONF_ONLINE_PLAYERS_COUNT){
    			NetworkChatManager.instance.Disconnect();
    
    			if( PhotonNetwork.isMasterClient ){
    				PhotonNetwork.LoadLevel( Constants.SCENE_NAME_PLAYER_SELECTION );
    			}
    		}
    	}
    

    New code:
    private void CheckConnectedPlayers(){
    		LobbyUIManager.instance.UpdatePlayerConnected( PhotonNetwork.room.playerCount );
    
    		if(PhotonNetwork.room.playerCount &gt;= Constants.CONF_ONLINE_PLAYERS_COUNT){
    			NetworkChatManager.instance.Disconnect();
    
    			Application.LoadLevel(Constants.SCENE_NAME_PLAYER_SELECTION);
    		}
    	}
    


    Note, I also tried to load the scene on IChatClientListener.OnDisconnected() but had the same crash problem...
  • Hello BuffOverFlow,

    I'm not using actually PhotonNetwork.LoadLevel on my side, I'd rather use Application.LoadLevel directly. I'm not facing the issues you guys are facing. I will do more test during the week-end.

    Cheers,
    Don T.
  • Thank you for your reply Don,

    Unfortunately the Application.LoadLevel solved the problem in one of my scene transitions (lobby to character selection scene), but I am still facing the problem in my main game scene...

    This is the scenario I am using for testing:

    1. I build the windows client on the unity project
    2. play the game lobby scene on unity
    3. start 2 game clients
    4. connect all the clients (including the unity one) to the chat server
    5. create a room on client 1 (unity)
    6. connect the client 2 to the room
    7. connect the client 3 to the room
    8. Once all clients had joined the room, loads the scene for character selection
    9. All clients select their characters
    10. Loads the game scene
    11. close the client 3
    12. client 3 freezes, I have to stop the client with windows task manager.
    13. I can stop client 1 and 2 without any problems, only the last client connected to the room freezes and no errors are displayed on logs

    On step 10 I tried to delay the scene load, but I am having the same problem:
        private void SelectPlayer(){
    		selectedPlayersCount++;
    
    		if( PhotonNetwork.isMasterClient ){
    			SetupBeforeLoad();
    
    			// all players selected
    			if(selectedPlayersCount &gt;= Constants.CONF_ONLINE_PLAYERS_COUNT){
    				StartCoroutine( LoadScene() );
    	        }
    		}
        }
    
        IEnumerator LoadScene(){
    		yield return new WaitForSeconds(5f);
    		Application.LoadLevel(Constants.SCENE_NAME_MANSION);
    	}
    
  • BuffOverflow, what do you mean exactly by "close or closing". Do you have an Exit button? Describe the process of closing and how it is triggered.
  • Its triggered by the X button from the window I am playing the game... I debugged it and the PhotonHandler.OnApplicationQuit is called, but for some reason, after the end of the OnApplicationQuit the window freezes.
  • Ok, mmm, I didn't faced such issue, but I'm not testing on PC either, only on iOS. This week-end I did test on 64 bits devices (iPhone5S and iPhone6) and didn't find any problem, I do see a bunch of compilation warning from Xcode but they seems harmless.

    Nevertheless, on my side I did rename the PhotonHandler.OnApplicationQuit by OnApplicationQuitPhoton and put it static, as I don't want it to be called when Unity quit. I call it manually from my main OnApplicationQuit handle. This is my main handler quit implementation.

    [code2=csharp]private void OnApplicationQuit()
    {
    GameManager.debugLog ("OnApplicationQuit(): application is quitting");

    // Cleanup Photon completelly.
    PhotonNetwork.LeaveRoom();
    PhotonNetwork.networkingPeer.SendOutgoingCommands();
    disconnectFromMPServer();
    PhotonHandler.OnApplicationQuitPhoton();

    this.Shutdown();
    GameManager.On_MP_Match_Launch -= onLaunchMatch;
    Everyplay.ThumbnailReadyAtFilePath -= ThumbnailReadyAtFilePathDelegate;
    }[/code2]

    Good luck in hunting your freeze issue bro.

    Cheers,
    Don T.
  • Don, thanks for reporting that fix for ObservedComponents. I just added this to PUN v1.52, too. I am just checking if there is a list and if it has any content. There should be no null components.

    I also made the socket wrapping classes IDisposable. That might have a positive effect on the editor freezing.
    The PhotonHandler.OnApplicationQuit() is there to make sure we disconnect when the app quits. As far as I could see, this is also essential for the Editor to not freeze. Maybe it's no longer needed with the Dispose() code and I am not sure (yet) how it affects PUN+.

    Is the loading of levels an issue??
  • No problem Tobias. Any timeline for v1.52? I'm just curious about the changes... but since I'm planning to release my game in August I'm pretty sure it will be out for that time and will probably upgrade.

    Regards,
    Don T.
  • Its still freezing the last client connected to the room. I tried some cleanup before quit, but nothing changed.

    PS: note that I also did the OnApplicationQuitPhoton stuff...
    public void OnApplicationQuit(){
    		MansionUIManager.instance.CleanUp();
    
    		foreach(GameObject pInstance in playerInstances){
    			PlayerScript pScript = pInstance.GetComponent&lt;PlayerScript&gt;();
    
    			pScript.CleanUp();
    		}
    
    		PhotonNetwork.LeaveRoom();
    		PhotonNetwork.networkingPeer.SendOutgoingCommands();
    		PhotonHandler.OnApplicationQuitPhoton();
    	}
    

    Checking the PhotonNetwork.SendOutgoingCommands() I see this code:
    public static void SendOutgoingCommands()
        {
            if (!VerifyCanUseNetwork())
            {
                return;
            }
    
            while (networkingPeer.SendOutgoingCommands())
            {
            }
        }
    

    Is there any other while loops like this? I want to debug all code that may cause the freezing issue...

    PS: just a reminder, I am using the latest PUN (not PUN+) and the latest unity 4.x PRO version.
    PS2: if I connect the latest client to the room using the windows client it freezes on closing the window and if I connect the latest client to the room using the Unity Editor it freezes on the next play.

    Regards,
    Junior
  • I just released 1.52 in the Asset Store. You should be able to update and re-import as usual.
    The changelog.txt has all the details. I hope you find the "Thanks Don" for one bug you reported (and I fixed).
  • Hi,

    I just bought the PUN+ version to see if the crash problem was solved but I am having this error connecting to the chat server:
    Connect() failed, because SocketImplementation or socket was null. Set PhotonPeer.SocketImplementation before Connect().
    

    I am connecting to the chat server as usual:
    void Start () {
    		connectedToChatServer = false;
    		Application.runInBackground = true;		// this must run in background or it will drop connection if not focussed.
    	}
    	
    	void Update () {
    		if (this.chatClient != null){
    			this.chatClient.Service();  		// make sure to call this regularly! it limits effort internally, so calling often is ok!
    		}
    	}
    	
    	public void ConnectToChat(string userName){
    		Debug.Log("Connecting to Chat Server...");
    		chatClient = new ChatClient(this);
    		chatClient.Connect(ChatAppId, "1.1", new ExitGames.Client.Photon.Chat.AuthenticationValues(userName));
    	}
    

    I am running on PC (windows) plataform.

    Please, help me!
  • Hi again,

    I changed the ChatPeer constructor from this:
    public ChatPeer(IPhotonPeerListener listener, ConnectionProtocol protocol) : base(listener, protocol)
            {
    #if UNITY
    #pragma warning disable 0162    // the library variant defines if we should use PUN's SocketUdp variant (at all)
                if (PhotonPeer.NoSocket)
                {
    #if !UNITY_EDITOR && (UNITY_PS3 || UNITY_ANDROID)
                    UnityEngine.Debug.Log("Using class SocketUdpNativeDynamic");
                    this.SocketImplementation = typeof(SocketUdpNativeDynamic);
    #elif !UNITY_EDITOR && UNITY_IPHONE
                    UnityEngine.Debug.Log("Using class SocketUdpNativeStatic");
                    this.SocketImplementation = typeof(SocketUdpNativeStatic);
    #elif !UNITY_EDITOR && (UNITY_WINRT)
                    // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
    #else
                    Type udpSocket = Type.GetType("ExitGames.Client.Photon.SocketUdp, Assembly-CSharp");
                    this.SocketImplementation = udpSocket;
                    if (udpSocket == null)
                    {
                        UnityEngine.Debug.Log("ChatClient could not find a suitable C# socket class. The Photon3Unity3D.dll only supports native socket plugins.");
                    }
    #endif
                    if (this.SocketImplementation == null)
                    {
                        UnityEngine.Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
                    }
                }
    #pragma warning restore 0162
    			if (protocol == ConnectionProtocol.WebSocket || protocol == ConnectionProtocol.WebSocketSecure) {
                	UnityEngine.Debug.Log("Using SocketWebTcp");
                	this.SocketImplementation = Type.GetType("ExitGames.Client.Photon.SocketWebTcp, Assembly-CSharp");//typeof(SocketWebTcp);
    			}
    #endif
            }
    

    To this:
    public ChatPeer(IPhotonPeerListener listener, ConnectionProtocol protocol) : base(listener, protocol)
            {
    	        Type udpSocket = Type.GetType("ExitGames.Client.Photon.SocketUdp, Assembly-CSharp");
    	        this.SocketImplementation = udpSocket;
    	        if (udpSocket == null)
    	        {
    	            UnityEngine.Debug.Log("ChatClient could not find a suitable C# socket class. The Photon3Unity3D.dll only supports native socket plugins.");
    	        }
    
    	        if (this.SocketImplementation == null)
    	        {
    	            UnityEngine.Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
    	        }
            }
    

    And its working now, I am not sure why it was not working.

    The crash I was having on the last client connected to the room is still happening, but I realized its related to the chat server connection... If I do not connect to the chat server the crash do not happen...
  • Ok guys, I just "fixed" the crash issue... The solution was never destroy the ChatManager I am using to manage the chat connections.

    I have tried all ways to safe disconnect before destroy my manager, but had no look, so I put a DontDestroyOnLoad(this) on my manager and leave it in peace...

    So the conclusion I got is that some open socket connection is causing the crash or some related with the LoadLevel I am doing after disconnect.

    Anyway, its working since I do not destroy the manager.

    Hope this help someone with the same problem.

    Regards
  • Oh, that's tricky. We didn't expect that, but it makes a lot of sense. Unity is not happy with lingering threads and doesn't kill them like MS runtime does.
    We can't promise a solution but we will look into this and maybe we can avoid the issue alltogether.

    Thanks for the update.
  • The GO that handles the client (no matter if chat or loadbalancing) needs to be marked as DontDestroyOnLoad. It has to be there all the time, because it's the listener for the client and used in some callbacks.

    Take care to implement OnApplicationQuit() and OnDestroy() to disconnect the client when either happens.