Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Android Chrome Browser (All others fine) get Memory Access Out Of Bounds.

Discussion in 'WebGL' started by Tset_Tsyung, Dec 2, 2021.

  1. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    406
    PLEASE NOTE: We are aware that Unity WebGL does not officialy support mobile browsers. However we've had success with this project on Firefox Mobile, and all PC browsers. Previously, the older sibling to this project worked fine on all Android browsers.

    Hi All,

    As stated in the title PC Browsers and Firefox on Android are fine. Our project involves downloading textures from the webserver that hosts the app so that we can show photospheres, similar to Google Earth.

    However, when we run this app on Android browsers Chrome and Opera Mini we get an error showing up stating "Memory Access Out Of Bounds".

    WhatsApp Image 2021-12-02 at 12.23.54.jpeg

    Interestingly enough, the android versions of Microsoft Edge and Firefox show no such error and work perfectly.

    I believe that the error is to do with how the images are being downloaded (code below), but can't seem to find settings to stop the crashing. I have a feeling that it may involve some security options, but am stumped as to how to proceed.

    Please Note: I have removed lines to do with setting up the URL. "_yOffset" is to adjust some of the texture images, as they were not all shot with correct orientation.

    Code (CSharp):
    1.     [System.Obsolete("This is not used as some posts stated this method was finishing early (???), please use LoadMapMKII")]
    2.     IEnumerator LoadMap(int _loc, string _subLocID, float _yOffset)
    3.     {
    4.  
    5.         /// Creation of the webRequest, and showing 'loading' image.
    6.  
    7.         yield return webRequest.SendWebRequest();
    8.  
    9.         if (webRequest.result != UnityWebRequest.Result.ConnectionError && webRequest.result != UnityWebRequest.Result.ProtocolError)
    10.         {
    11.             /// Add to list of textures w/ time for deleting oldest (#memorymanagement)
    12.             locationTextures.Add(_loc.ToString() + _subLocID, new TextureTimeStruct(((DownloadHandlerTexture)webRequest.downloadHandler).texture, Time.time));
    13.             Material mat = new Material(skyboxShader);
    14.             mat.mainTexture = locationTextures[_loc.ToString() + _subLocID].Texture;
    15.             RenderSettings.skybox = mat;
    16.             RenderSettings.skybox.SetFloat("_Rotation",90f + _yOffset);
    17.  
    18.             Debug.Log("Result: " + webRequest.result + ". Dimensions: " + mat.mainTexture.width + "*" + mat.mainTexture.height);
    19.         }
    20.         else
    21.             Debug.LogError("Failed attempting to get URL " + newUrl + ". See error below:\n" + webRequest.result);
    22.     }
    23.  
    24.     IEnumerator LoadMapMKII(int _loc, string _subLocID, float _yOffset)
    25.     {
    26.  
    27.         /// Creation of the webRequest, and showing 'loading' image.
    28.  
    29.         yield return webRequest.SendWebRequest();
    30.  
    31.         if (webRequest.result != UnityWebRequest.Result.ConnectionError && webRequest.result != UnityWebRequest.Result.ProtocolError)
    32.         {
    33.            /// Manually create the new texture and 'LoadImage' from the byte stream
    34.             DownloadHandlerTexture _handler = ((DownloadHandlerTexture)webRequest.downloadHandler);
    35.             int _width = _handler.texture.width;
    36.             int _height = _handler.texture.height;
    37.             Texture2D _tex = new Texture2D(_width, _height);
    38.             _tex.LoadImage(_handler.data);
    39.  
    40.             /// Add to list of textures w/ time for deleting oldest (#memorymanagement)
    41.             locationTextures.Add(_loc.ToString() + _subLocID, new TextureTimeStruct(_tex, Time.time));
    42.             Material mat = new Material(skyboxShader);
    43.             mat.mainTexture = locationTextures[_loc.ToString() + _subLocID].Texture;
    44.             RenderSettings.skybox = mat;
    45.             RenderSettings.skybox.SetFloat("_Rotation", 90f + _yOffset);
    46.  
    47.             Debug.Log("Result: " + webRequest.result + ". Dimensions: " + mat.mainTexture.width + "*" + mat.mainTexture.height);
    48.         }
    49.         else
    50.             Debug.LogError("Failed attempting to get URL " + newUrl + ". See error below:\n" + webRequest.result);
    51.     }
    Please note, that the URL being requested isn't the issue - this has been checked.

    As usual, any assistance with this would be greatly appreciated.
     
    Last edited: Dec 2, 2021
  2. MarcelPursche

    MarcelPursche

    Unity Technologies

    Joined:
    Mar 3, 2021
    Posts:
    44
    Hi,

    the amount of memory that can be used in mobile browsers is pretty limited. Additionally, there is a known issue with Chrome Android that prevents the growth of the WASM heap over a certain threshold(~256 MB): https://forum.unity.com/threads/and...located-memory-above-256mb-confirmed.1014475/. The overall size limit of the WASM heap is much higher for Chrome Android but only if the initial size of the WASM heap is set to this larger size. In Unity 2022.1 we added some new build options to control the initial size of the WASM heap and how the WASM heap growths. With these options it is possible to work around the restrictions of Android Chrome.
     
    Tset_Tsyung likes this.
  3. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    406
    Many thanks for the reply @MarcelPursche.

    I'm working around the issue by manly calling for garbage collection. I don't like doing it, but it hasn't crashed since. In the meantime, I'll wait for a version of Unity 2022 that we're happy to upgrade to.

    Mike