Photon won't start on first install on Samsung devices

Options
Hi there,

I'm having a really weird error that I have no idea how to fix. When I first install my game to Android, either through Google Play or through my USB, on the first install it doesn't connect to Photon. I actually setup a temporary popup that notifies the user about it and asks them to restart their device. It does work however after the restart and any other attempts afterwards without any issues. I'm using Logcat to try and figure out what the issue is and the following is what I'm getting:


Any ideas on what I could try to make it work off the first install? Or is this normal behavior? The issue so far has occurred on my Note 3 phone and on a friend's Samsung S7. I also have an Android Nexus 11inch 2013 tablet and there I have no issues so it looks like it's on Samsung Android devices only. There are also no issues on my iPhone 7 plus.

Thanks in advance!

Comments

  • stefanplc
    Options
    Btw, the log in the screenshot that I posted is what gets spammed over and over and over again when the game tries the start. The game first checks for a php file to ensure the database connection is fine. If that connects properly, it then checks for PhotonNetwork.connecting, PhotonNetwork.connected and PhotonNetwork.connectionStateDetailed and if it's connected it lets the game start. The PhotonNetwork.connectionStateDetailed is sent to a text field via update() so I have a visual cue too and on the first install the text field doesn't change at all so it doesn't appear to be working.
  • stefanplc
    stefanplc
    edited May 2017
    Options
    I added one of those mobile console plugins and here's what I'm getting when the error happens:


  • stefanplc
    stefanplc
    edited May 2017
    Options
    Here's a simplified version of the code that I'm using:
    void Start () {
            StartCoroutine("CheckGameStatus");
        }
    
        IEnumerator CheckGameStatus() {
            WWW GameStatusPost = new WWW(DatabaseInfo.Instance.GetGameStatusURL());
            yield return GameStatusPost; // Wait until the download is done
            Data = GameStatusPost.text.Split(new string[] { " | " }, StringSplitOptions.None);
    
            if (Data[0] == "Version 1.1") {
    
                // This is where the code gets the error and stops
    
                if (PhotonNetwork.connecting) {
                    Loading.SetActive(true); // loading animation
                    yield return new WaitForSeconds(1f);
                }
    
                if (PhotonNetwork.connected) {
                    Loading.SetActive(false);
                    StartGame();
                } else {
                    StartCoroutine("TryAgain");
                }
    
            }
        }
    
        IEnumerator TryAgain() {
            yield return new WaitForSeconds(2f);
            if (!PhotonNetwork.connected && !PhotonNetwork.connecting) {
                PhotonNetwork.ConnectUsingSettings(DatabaseInfo.Instance.GetGameVersion());
                StartCoroutine("TryAgainTwo");
            }
        }
    
        IEnumerator TryAgainTwo() {
            yield return new WaitForSeconds(2f);
            if (!PhotonNetwork.connected && !PhotonNetwork.connecting) {
                FindBestServer();
            }
    
            yield return new WaitForSeconds(4f);
    
            if (PhotonNetwork.connected) {
                Loading.SetActive(false);
            } else {
                PhotonErrorPopup.SetActive(false);
            }
        }
    
        public void StartGame() {
            //start game code
        }
    
        public void FindBestServer() {
            //code that pings all available servers and then connects to the best one
        }
    This was happening on both Unity 5.5 and 5.6 using Photon 1.83
  • stefanplc
    Options
    bump
  • stefanplc
    Options
    is there anything else that I can do to help solve this issue?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @stefanplc,

    Just to confirm, this issue is the same as the one you reported here right? And it happens on a single device yes?
  • Tobias
    Options
    If this issue is only on that one device, we would need your help debugging this. We don't have that device.

    It seems like the static constructor of PhotonNetwork is having an issue and you could probably find the exact place by using try-catch blocks to narrow down the area and finally find it.

    The issue might be caused by timing. Some of your scripts might be run earlier than usual, use PhotonNetwork and cause the issue.
    It would be interesting to know if any of our demos from PUN has the same issue on device?
  • stefanplc
    Options
    @JohnTube Yes, it's the same issue. I've had it happen on my Note 3, which is the device that I use as the "oldest device I'd like the game to still run fine on", so I thought it was due to it being an older device, but another tester using a Samsung S7 or S8 reported having the same issue too a few weeks ago. If they restart their device, it works, otherwise it doesn't. On my Nexus 7 tablet which is from around the same time period, it works just fine. A couple of days ago, someone else mentioned running into a similar issue on an iPhone 7, however after updating from PUN 1.83 to PUN 1.84 and publishing an update it worked for them. The weird thing though is that it was all working just fine on my own iPhone 7 Plus and on an iPAD. The only difference is that I'm playing from Europe and they're playing from USA. The iPhone user mentioned trying the game on a few different connections without any positive results prior to the PUN update.

    A workaround I that I'm using right now is to have the following run in update: Status.text = PhotonNetwork.connectionStateDetailed.ToString(); . If the PhotonNetwork script won't start, then the text value doesn't change. I then check 5 seconds later to see if the text value is different and if it's not, I show an error message asking the user to restart their device.

    To try and narrow down the problem, I'm going to create a new project sometimes in the next day or two that'll only have the connection script, check to see if I run into the same issue and then if I do, post the project here so you guys can check it out.

    Meanwhile, if you'd like, you can see the game live on the iOS or Android stores. Just visit www.tomeofheroes.com, click download and then pick your platform. Once the game is opened, you can draw a circle with your finger on the screen to open the console. The Android version with the console should be up in a couple of hours, it's currently processing the update. On iOS it got approved a few hours ago so that's live.

    Thanks for the replies!
  • stefanplc
    Options
    Sorry about the very delayed response, been busy with a few other things. I ended up finding the issue: The scenario mentioned above happens when "Split Application Binary" under Player Settings > Publish Settings is turned on. Turning it off fixes the issue, however my game is larger than 100mb so I'm not sure what to do now as I can't publish on the Google Store as a result... Any thoughts?
  • stefanplc
    Options
    To reproduce the bug, just create a new project and import the Photon Unity Networking and Unity Logs Viewer assets. Create a new c# script and in Start() just add PhotonNetwork.ConnectingUsingSettings("0.1"); and then Build and Run to an Android device. You should be getting similar results to the screenshots posted earlier in this forum post. Thanks!
  • stefanplc
    Options
    Hi there,
    I found a solid solution for this issue. It might be standard practice for many developers and that's why they didn't run into the same bug that I did. Long story short is to just create a new scene as your first one (the one with the index 0) and have that scene then send you to the primary one. The point is to just not use Photon in your first scene. If you take a look at https://docs.unity3d.com/Manual/android-OBBsupport.html it explains how "APK - Consists of the executables (Java and native), plug-ins, scripts, and the data for the first Scene (with the index 0).". So what you want is to not have the Photon be put in the APK but in the OBB which "Contains everything else, including all of the remaining Scenes, resources, and streaming Assets.".

    In case you run into the "java.io.FileNotFoundException : assets/build_info.txt" error which I did during my tests, you need to add to your manifest, but that's another story.

    Thanks!
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @stefanplc,

    I'm glad you solved it finally.
    We appreciate it that your are sharing the solution with the community.
    I wish I could've helped you more with this.
  • stefanplc
    Options
    Happy it worked out!