Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Running out of memory when using 1.4GB on 6GB device but 4GB devices are fine.

Discussion in 'General Discussion' started by trooper, Feb 22, 2021.

  1. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    694
    I'm running the same build on both devices, both using full textures a Samsung Galaxy S8 (4GB) and POCOPHONE F1 (6GB).

    I start the game then whilst it's running i switch the textures to full (from half):
    UnityEngine.QualitySettings.masterTextureLimit = 0;

    The poco cannot go above 1.2GBish of total memory usage before it crashes (about 0.8GB of texture memory)

    Adreno-GSL: <gsl_memory_alloc_pure:2297>: GSL MEM ERROR: kgsl_sharedmem_alloc ioctl failed.: au.com.oddgames.trucksoffroad

    Adreno-GSL: <sharedmem_gpuobj_alloc:2713>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory: au.com.oddgames.trucksoffroad


    upload_2021-2-22_14-24-39.png

    The samsung s8 and note 5 can handle full textures no problem.

    I'm thinking it might be a chipset problem / hardware problem (Adreno 630)

    Anyone else experienced hard memory limits around 1.2gb on similar devices?
     
  2. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    694
    Running this code the Note 5 was able to get to 108 textures but the Poco could only create 68 textures.

    The samsung reports lower system and gpu memory than the poco.

    Reading proc/memory doesn't give me any decent results on samsung for available memory and free on both devices is very similar so I can use that to lower texture settings for these edge cases.

    Code (CSharp):
    1.  
    2. public class GenerateTextures : MonoBehaviour
    3. {
    4.  
    5.     List<RenderTexture> textures = new List<RenderTexture>();
    6.  
    7.     // Start is called before the first frame update
    8.     IEnumerator Start()
    9.     {
    10.         int i = 0;      
    11.  
    12.  
    13.         while(Application.isPlaying)
    14.         {
    15.  
    16.             var a = new RenderTexture(2048, 2048, 8);
    17.            
    18.             Graphics.Blit(null, a);
    19.  
    20.             textures.Add(a);
    21.  
    22.             Graphics.DrawTexture(new Rect(0,0,100,100), a);
    23.  
    24.             yield return new WaitForSeconds(1);
    25.  
    26.             i++;
    27.         }
    28.  
    29.     }
    30.  
    31. }
    32.  
     
  3. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    694
    Using MemoryInfo I get these results (poco phone top, note 5 bottom). The Note 5 is working well, it crashes out when the memory gets low but the poco seems to want to hover at 960mb (there was 1 time when I could get lower but I have no idea why it did that).

    Poco started with 1646 available
    Note 5 started with 1707 available

    upload_2021-2-22_16-8-20.png
     
  4. JosephHK

    JosephHK

    Joined:
    Jan 28, 2015
    Posts:
    39
    Can you solve this issue?
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,544
    I've experienced limits much lower than that.

    At this point, it doesn't really matter all that much how much ram a phone has, it's there for multitasking, not so one app can take it all (or even a big chunk of it). The OS has a hard limit of RAM for each APP.

    Maybe these phones have different OSes with different limits and memory management?
     
    Last edited: Apr 7, 2021
    MadeFromPolygons and Ryiah like this.
  6. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    694
    It could be. But ideally the OS should let us know how much we can use via the threshold. But after a bit more testing I'm fairly confident the issue is that the GPU limits differ from overall ram and some are allowed to go much further than others.
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,544
    Pretty sure there are APIs in both iOS and Android to help with that.

    Plus both OSes send warnings when you pass the memory limit. If you don't reduce memory usage soon after receiving the warnings, your app gets terminated.

    AFAIK Unity doesn't do anything in response to those warnings, nor is there a super easy way to access them from Unity.
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    16,618
    An event you can register has been available since Unity 5.6. If you unload assets in response to this you can prevent the termination.

    https://docs.unity3d.com/ScriptReference/Application-lowMemory.html
     
    Joe-Censored, AcidArrow and andyz like this.
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,544
  10. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    694
    That's right, my original post is using them, they don't work on all devices accurately or at least they don't report limits for the GPU.

    This is how you get it on Android, iOS doesn't seem to have any problems reporting memory available so that's a non issue.

    Code (CSharp):
    1.     static AndroidJavaObject getMemoryInfo()
    2.     {
    3.         AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    4.         AndroidJavaObject currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
    5.         AndroidJavaObject systemService = currentActivity.Call<AndroidJavaObject>("getSystemService", "activity");
    6.         AndroidJavaObject memoryInfo = new AndroidJavaObject("android.app.ActivityManager$MemoryInfo");
    7.         systemService.Call("getMemoryInfo", memoryInfo);
    8.  
    9.         return memoryInfo;
    10.     }
     
    AcidArrow likes this.
  11. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    694
    This works great on my Note 5 but it never fires on my POCOPHONE F1 and that is also correct because the OS is reporting that there is plenty of memory available right before it crashes. Definitely a per device or gpu problem, not unity.
     
unityunity