Search Unity

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.

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

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    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:
    748
    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:
    748
    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:
    40
    Can you solve this issue?
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,799
    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
  6. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    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:
    11,799
    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:
    21,205
    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
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,799
  10. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    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:
    748
    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.
     
  12. Tomsterk

    Tomsterk

    Joined:
    Nov 23, 2012
    Posts:
    10
    Has anyone found a solution to this problem? Our app runs perfectly fine on iOS, but won't load more than a few meshes with textures. Textures and meshes are all reduced as much as possible on import. Doesn't matter if we load the assets in via Instantiate or if they exist in scene when it loads.
     
Thread Status:
Not open for further replies.