Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Bug? Generated UnityLoader.js fails in iOS 14 public beta

Discussion in 'WebGL' started by mike_unity414, Jul 30, 2020.

Thread Status:
Not open for further replies.
  1. mike_unity414

    mike_unity414

    Joined:
    May 18, 2020
    Posts:
    3
    Unity: Unity 2019.4.5f1
    Device A: Macbook Pro; Mac OS Big Sur Preview
    Device B: iPhoneX; iOS 14 beta
    Browser: Safari


    Forgive the snippet here, but this is from the generated UnityLoader.js that the webgl build produces in Unity. This is approximately line 3, col 31,796. The line in question is:

    case"Mac OS X":p=/Mac OS X (10[\.\_\d]+)/.exec(i)[1];



    The navigator.appVersion (which seems to be the string this is parsing out) yields something along the lines of
    5.0 (Macintosh; Intel Mac OS X 11_0)


    As such, the assumption that it starts with a '10' is wrong, and there is no index 1 in the result of the regex, it throws an exception, and unity fails to load.

    I have hacked around this, without fully understanding the context or intent of this code snippet, by *ignoring* the generated UnityLoader.js, using my own fork, and just replacing it with this obviously wrong but non exception throwing code:
    case"Mac OS X":p=function(){let x = /Mac OS X (10[\.\_\d]+)/.exec(i); return x ? x[1] : "10_15_6"}();


    I think this is a bug. But also, if this is somehow my fault and I should tune some build paramter somewhere, please tell me as such :p
     
    Last edited: Jul 30, 2020
  2. Joel4763

    Joel4763

    Joined:
    Dec 5, 2015
    Posts:
    1
    macOS Big Sur just recently received a public beta, and is now officially macOS 11, it worked in the developer beta because it had a bug which displayed the version as 10.16.

    Unity won't update the public Unity builds until macOS Big Sur is in full release.
    If you want a quick fix, open UnityLoader.js in your favorite code editor, and find a line with this text, "p = /Mac OS X (10[\.\_\d]+)/.exec(i)[1];", change it to "p = /Mac OS X (1[\.\_\d][\.\_\d]+)/.exec(i)[1];"

    This will allow it to run on macOS 10.*.* to macOS 19.*.*

    Your Welcome!
     
  3. sandstonealan

    sandstonealan

    Joined:
    Nov 9, 2018
    Posts:
    1
    Thank you mike_unity414 for raising the issue and a massive thank you to Joel4763 for being a lifesaver.

    If anyone needs to fix this in Unity 2017 LTS, there is one difference to the 2019 code. 2017 has:
    Code (JavaScript):
    1. p = /Mac OS X (10[\.\_\d]+)/.exec(a)[1];
    So exec(a) not exec(i) and that needs to be reflected in Joel4763's replacement code of course:
    Code (JavaScript):
    1. p = /Mac OS X (1[\.\_\d][\.\_\d]+)/.exec(a)[1];
     
    bvicil likes this.
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    827
    Thanks for reporting! Marked down a TODO for the team to fix this up.
     
  5. unity_8ddK5l7kqhCdSQ

    unity_8ddK5l7kqhCdSQ

    Joined:
    Sep 29, 2017
    Posts:
    1
    Also when working on this, it is a good idea to check if exec returns an actual array and not just a null value
     
    jukka_j likes this.
  6. Unity1990

    Unity1990

    Joined:
    Jan 19, 2016
    Posts:
    12
    Hi, any update on this? I'm facing on this problem with unity 2020.1.8f1 and Big Sur official release
     
  7. Unity1990

    Unity1990

    Joined:
    Jan 19, 2016
    Posts:
    12
    using the above discussion, i wrote this script that replace the wrong regex with a working regex automatically after build.
    Put this under Assets/Scripts/Editor

    Code (CSharp):
    1. using System.IO;
    2. using UnityEditor;
    3. using UnityEditor.Callbacks;
    4. using UnityEngine;
    5.  
    6. public class WebglPostBuild
    7. {
    8.     [PostProcessBuild(1)]
    9.     public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
    10.     {
    11.         if (target != BuildTarget.WebGL)
    12.             return;
    13.  
    14.         Debug.Log(pathToBuiltProject);
    15.  
    16.         string[] filePaths = Directory.GetFiles(pathToBuiltProject, "*.js", SearchOption.AllDirectories);
    17.  
    18.         foreach(string file in filePaths)
    19.         {
    20.             if(file.ToLower().Contains("loader.js"))
    21.             {
    22.                 string text = File.ReadAllText(file);
    23.                 text = text.Replace(@"Mac OS X (10[\.\_\d]+)", @"Mac OS X (1[\.\_\d][\.\_\d]+)");
    24.                 File.WriteAllText(file, text);
    25.             }
    26.         }
    27.     }
    28. }
     
    fherbst, yoneki, dblaw and 5 others like this.
  8. pedro_unity228

    pedro_unity228

    Joined:
    Jul 3, 2018
    Posts:
    4
    Thanks for the solution above! FYI the "loader.js" check doesn't work for us in production mode, so we just replaced on all JS files (there were just two of them total).
     
  9. Kobro

    Kobro

    Joined:
    Aug 7, 2013
    Posts:
    3
    Same problems as above in Big Sur. None of our WebGL releases will execute in Chrome.

    The above fix didn't solve it for is in a quick test, but will investigate further. Using Unity 2019.3.15f1
     
    marioslokas-v likes this.
  10. marioslokas-v

    marioslokas-v

    Joined:
    Aug 19, 2020
    Posts:
    12
    Same problem here. The solution were I modify the UnityLoader.js file does not seem to work. Anyone got it working, or do we need to upgrade Unity?

    EDIT: After locating issue #1284215 about the same problem one of the suggested solutions worked for me (version 2019.3.6f1): replace "/Mac OS X (10[\.\_\d]+)/.exec(i)[1];" with
    "/Mac OS X (1[0-1][\.\_\d]+)/.exec(i)[1];" inside UnityLoader.js (replacing the 10 with 1[0-1]).
    Hope to see a fix from Unity soon.
     
    Last edited: Dec 1, 2020
  11. xavicarosilvente

    xavicarosilvente

    Joined:
    Nov 8, 2018
    Posts:
    7
    Why does it not work for me?

    case "Mac OS X":
    osVersion = /Mac OS X (1[\.\_\d][\.\_\d]+)/.exec(nAgt)[1];
    break;

    upload_2020-12-10_15-31-39.png
     
  12. Admor-DM-ED

    Admor-DM-ED

    Joined:
    Jan 25, 2019
    Posts:
    1
  13. shochet

    shochet

    Joined:
    Dec 17, 2013
    Posts:
    22
    Unity 2019.4.16 contained this fix, but they did not tag the bug for some reason. Tested and working for us.
    • WebGL: Fixed a crash with Unity web loader on new macOS Big Sur.
     
    Admor-DM-ED likes this.
  14. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    827
    It looks like what was a pre-release Safari issue (that then wasn't a Safari issue when macOS Big Sur actually released), now raised its head on Chrome. See this stickied thread https://forum.unity.com/threads/bug...ort-for-chrome-edge-on-macos-big-sur.1048310/ for more information and ways to remedy.

    Since we have a few threads opened about this, let's consolidate conversation to that "official" sticky thread, and I'll go ahead and close this one. Thanks for reporting, and sorry for the trouble!
     
Thread Status:
Not open for further replies.
unityunity