GL_OUT_OF_MEMORY 和 android 应用程序使用 unity 崩溃?
GL_OUT_OF_MEMORY and android app crashing using unity?
我试图在 运行 时间从我的 AR project.While 的许多图像链接将图像加载到图像库中,测试下面的代码 android 应用因以下错误而崩溃
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.IO;
public class DynamicImageLib : MonoBehaviour
{
public ARTrackedImageManager aRTrackedImageManager;
public GameObject mTrackedImagePrefab;
public Texture2D imgToTexture2d;
public MutableRuntimeReferenceImageLibrary myRuntimeImageLibrary;
public Text msgText;
public Text numText;
bool isRunning = false;
List<string> allURLs = new List<string> { "https://i.picsum.photos/id/0/5616/3744.jpg", "https://i.picsum.photos/id/1001/5616/3744.jpg",
"https://i.picsum.photos/id/1000/5626/3635.jpg","https://i.picsum.photos/id/1004/5616/3744.jpg","https://i.picsum.photos/id/1005/5760/3840.jpg",
"https://i.picsum.photos/id/1006/3000/2000.jpg","https://i.picsum.photos/id/1008/5616/3744.jpg","https://i.picsum.photos/id/1009/5000/7502.jpg",
"https://i.picsum.photos/id/101/2621/1747.jpg","https://i.picsum.photos/id/1010/5184/3456.jpg","https://i.picsum.photos/id/1011/5472/3648.jpg",
"https://i.picsum.photos/id/1012/3973/2639.jpg","https://i.picsum.photos/id/1013/4256/2832.jpg","https://i.picsum.photos/id/1014/6016/4000.jpg",
"https://i.picsum.photos/id/1015/6000/4000.jpg","https://i.picsum.photos/id/1016/3844/2563.jpg","https://i.picsum.photos/id/1018/3914/2935.jpg",
"https://i.picsum.photos/id/1019/5472/3648.jpg","https://i.picsum.photos/id/102/4320/3240.jpg","https://i.picsum.photos/id/1020/4288/2848.jpg",
"https://i.picsum.photos/id/1021/2048/1206.jpg","https://i.picsum.photos/id/1022/6000/3376.jpg","https://i.picsum.photos/id/1023/3955/2094.jpg",
"https://i.picsum.photos/id/1024/1920/1280.jpg","https://i.picsum.photos/id/1025/4951/3301.jpg"};
void Awake()
{
Screen.sleepTimeout = SleepTimeout.NeverSleep;
aRTrackedImageManager = gameObject.AddComponent<ARTrackedImageManager>();
aRTrackedImageManager.enabled = false;
myRuntimeImageLibrary = aRTrackedImageManager.CreateRuntimeLibrary() as MutableRuntimeReferenceImageLibrary;
aRTrackedImageManager.maxNumberOfMovingImages = 1;
aRTrackedImageManager.trackedImagePrefab = mTrackedImagePrefab;
aRTrackedImageManager.trackedImagesChanged += OnImageChanged;
}
// Start is called before the first frame update
void Start()
{
Debug.Log("Intially Running................................................");
// StartCoroutine(AddImageTrackerByUrl("https://upload.wikimedia.org/wikipedia/commons/9/97/The_Earth_seen_from_Apollo_17.jpg"));
//StartCoroutine(AddImageTrackerByUrl("https://upload.wikimedia.org/wikipedia/commons/9/97/The_Earth_seen_from_Apollo_17.jpg[/URL]"));
//StartCoroutine(AddImageTrackerByUrl("https://i.picsum.photos/id/0/5616/3744.jpg"));
//StartCoroutine(AddImageTrackerByUrl("https://i.picsum.photos/id/1001/5616/3744.jpg"));
StartCoroutine(AddImageTrackerByUrl());
}
// Update is called once per frame
void Update()
{
}
public void OnImageChanged(ARTrackedImagesChangedEventArgs args)
{
foreach (var trackedImage in args.added)
{
Debug.Log(trackedImage.name);
msgText.text = trackedImage.name;
}
}
IEnumerator AddImageTrackerByUrl()
{
isRunning = true;
aRTrackedImageManager.enabled = false;
if (aRTrackedImageManager.descriptor.supportsMutableLibrary)
{
foreach (var link in allURLs)
{
using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(link))
{
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError || webRequest.isHttpError)
{
Debug.Log("Error is " + webRequest.error);
}
else
{
imgToTexture2d = DownloadHandlerTexture.GetContent(webRequest);
Unity.Jobs.JobHandle jobHandle = myRuntimeImageLibrary.ScheduleAddImageJob(imgToTexture2d, Path.GetFileName(link), 0.2f);
jobHandle.Complete();
if (myRuntimeImageLibrary != null)
{
Debug.Log("Image Library Count: " + myRuntimeImageLibrary.count);
numText.text = myRuntimeImageLibrary.count.ToString();
aRTrackedImageManager.referenceLibrary = myRuntimeImageLibrary;
}
webRequest.downloadHandler.Dispose();
imgToTexture2d = null;
aRTrackedImageManager.enabled = true;
}
}
}
}
}
}
日志报错如下
Error Unity OPENGL NATIVE PLUG-IN ERROR: GL_OUT_OF_MEMORY: Not enough memory left to execute command
Error Unity (Filename: ./Runtime/GfxDevice/opengles/GfxDeviceGLES.cpp Line: 353)
Error Unity OPENGL NATIVE PLUG-IN ERROR: GL_OUT_OF_MEMORY: Not enough memory left to execute command
Error Unity (Filename: ./Runtime/GfxDevice/opengles/GfxDeviceGLES.cpp Line: 353)
Error Unity Could not allocate memory: System out of memory!
Error Unity Trying to allocate: 72192000B with 16 alignment. MemoryLabel: NativeArray
Error Unity Allocation happened at: Line:59 in
Error Unity Memory overview
Error Unity [ ALLOC_TEMP_THREAD ] used: 32768B | peak: 0B | reserved: 2752512B
Error Unity [ ALLOC_TEMP_JOB_1_FRAME ] used: 0B | peak: 0B | reserved: 3145728B
Error Unity [ ALLOC_TEMP_JOB_2_FRAMES ] used: 0B | peak: 0B | reserved: 1048576B
Error Unity [ ALLOC_TEMP_JOB_4_FRAMES ] used: 0B | peak: 0B | reserved: 2097152B
Error Unity [ ALLOC_TEMP_JOB_ASYNC ] used: 4326745B | peak: 0B | reserved: 7340032B
Error Unity [ ALLOC_DEFAULT ] used: 15634711B | peak: 165212737B | reserved: 15974431B
Error Unity [ ALLOC_GAMEOBJECT ] used: 820820B | peak: 820952B | reserved: 823005B
Error Unity [ ALLOC_GFX ] used: 777844463B | peak: 777844463B | reserved: 777845964B
Error Unity (Filename: Line: 1449)
它最初下载了一些图像并添加到库中,crashes.Is 因为下载的图像很大?我试图通过使用 webrequest datahandler dispose 方法释放大小,但没有 effect.How 来解决与内存相关的 issues.Any 指南?
Error Unity Could not allocate memory: System out of memory!
Error Unity Trying to allocate: 72192000B with 16 alignment. MemoryLabel: NativeArray
看来你的贴图分辨率很高。此外,它们似乎未压缩。
纹理大小:6000 * 4000 * 4(RGBA) = 96MB
使用更小或压缩的纹理。
最好在将图像上传到 GPU 之前降低图像的分辨率并进行压缩。理想情况下,纹理大小应该是两侧的二次方。这些尺寸如下:2、4、8、16、32、64、128、256、512、1024、2048 或 4096 像素。
我试图在 运行 时间从我的 AR project.While 的许多图像链接将图像加载到图像库中,测试下面的代码 android 应用因以下错误而崩溃
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.IO;
public class DynamicImageLib : MonoBehaviour
{
public ARTrackedImageManager aRTrackedImageManager;
public GameObject mTrackedImagePrefab;
public Texture2D imgToTexture2d;
public MutableRuntimeReferenceImageLibrary myRuntimeImageLibrary;
public Text msgText;
public Text numText;
bool isRunning = false;
List<string> allURLs = new List<string> { "https://i.picsum.photos/id/0/5616/3744.jpg", "https://i.picsum.photos/id/1001/5616/3744.jpg",
"https://i.picsum.photos/id/1000/5626/3635.jpg","https://i.picsum.photos/id/1004/5616/3744.jpg","https://i.picsum.photos/id/1005/5760/3840.jpg",
"https://i.picsum.photos/id/1006/3000/2000.jpg","https://i.picsum.photos/id/1008/5616/3744.jpg","https://i.picsum.photos/id/1009/5000/7502.jpg",
"https://i.picsum.photos/id/101/2621/1747.jpg","https://i.picsum.photos/id/1010/5184/3456.jpg","https://i.picsum.photos/id/1011/5472/3648.jpg",
"https://i.picsum.photos/id/1012/3973/2639.jpg","https://i.picsum.photos/id/1013/4256/2832.jpg","https://i.picsum.photos/id/1014/6016/4000.jpg",
"https://i.picsum.photos/id/1015/6000/4000.jpg","https://i.picsum.photos/id/1016/3844/2563.jpg","https://i.picsum.photos/id/1018/3914/2935.jpg",
"https://i.picsum.photos/id/1019/5472/3648.jpg","https://i.picsum.photos/id/102/4320/3240.jpg","https://i.picsum.photos/id/1020/4288/2848.jpg",
"https://i.picsum.photos/id/1021/2048/1206.jpg","https://i.picsum.photos/id/1022/6000/3376.jpg","https://i.picsum.photos/id/1023/3955/2094.jpg",
"https://i.picsum.photos/id/1024/1920/1280.jpg","https://i.picsum.photos/id/1025/4951/3301.jpg"};
void Awake()
{
Screen.sleepTimeout = SleepTimeout.NeverSleep;
aRTrackedImageManager = gameObject.AddComponent<ARTrackedImageManager>();
aRTrackedImageManager.enabled = false;
myRuntimeImageLibrary = aRTrackedImageManager.CreateRuntimeLibrary() as MutableRuntimeReferenceImageLibrary;
aRTrackedImageManager.maxNumberOfMovingImages = 1;
aRTrackedImageManager.trackedImagePrefab = mTrackedImagePrefab;
aRTrackedImageManager.trackedImagesChanged += OnImageChanged;
}
// Start is called before the first frame update
void Start()
{
Debug.Log("Intially Running................................................");
// StartCoroutine(AddImageTrackerByUrl("https://upload.wikimedia.org/wikipedia/commons/9/97/The_Earth_seen_from_Apollo_17.jpg"));
//StartCoroutine(AddImageTrackerByUrl("https://upload.wikimedia.org/wikipedia/commons/9/97/The_Earth_seen_from_Apollo_17.jpg[/URL]"));
//StartCoroutine(AddImageTrackerByUrl("https://i.picsum.photos/id/0/5616/3744.jpg"));
//StartCoroutine(AddImageTrackerByUrl("https://i.picsum.photos/id/1001/5616/3744.jpg"));
StartCoroutine(AddImageTrackerByUrl());
}
// Update is called once per frame
void Update()
{
}
public void OnImageChanged(ARTrackedImagesChangedEventArgs args)
{
foreach (var trackedImage in args.added)
{
Debug.Log(trackedImage.name);
msgText.text = trackedImage.name;
}
}
IEnumerator AddImageTrackerByUrl()
{
isRunning = true;
aRTrackedImageManager.enabled = false;
if (aRTrackedImageManager.descriptor.supportsMutableLibrary)
{
foreach (var link in allURLs)
{
using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(link))
{
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError || webRequest.isHttpError)
{
Debug.Log("Error is " + webRequest.error);
}
else
{
imgToTexture2d = DownloadHandlerTexture.GetContent(webRequest);
Unity.Jobs.JobHandle jobHandle = myRuntimeImageLibrary.ScheduleAddImageJob(imgToTexture2d, Path.GetFileName(link), 0.2f);
jobHandle.Complete();
if (myRuntimeImageLibrary != null)
{
Debug.Log("Image Library Count: " + myRuntimeImageLibrary.count);
numText.text = myRuntimeImageLibrary.count.ToString();
aRTrackedImageManager.referenceLibrary = myRuntimeImageLibrary;
}
webRequest.downloadHandler.Dispose();
imgToTexture2d = null;
aRTrackedImageManager.enabled = true;
}
}
}
}
}
}
日志报错如下
Error Unity OPENGL NATIVE PLUG-IN ERROR: GL_OUT_OF_MEMORY: Not enough memory left to execute command
Error Unity (Filename: ./Runtime/GfxDevice/opengles/GfxDeviceGLES.cpp Line: 353)
Error Unity OPENGL NATIVE PLUG-IN ERROR: GL_OUT_OF_MEMORY: Not enough memory left to execute command
Error Unity (Filename: ./Runtime/GfxDevice/opengles/GfxDeviceGLES.cpp Line: 353)
Error Unity Could not allocate memory: System out of memory!
Error Unity Trying to allocate: 72192000B with 16 alignment. MemoryLabel: NativeArray
Error Unity Allocation happened at: Line:59 in
Error Unity Memory overview
Error Unity [ ALLOC_TEMP_THREAD ] used: 32768B | peak: 0B | reserved: 2752512B
Error Unity [ ALLOC_TEMP_JOB_1_FRAME ] used: 0B | peak: 0B | reserved: 3145728B
Error Unity [ ALLOC_TEMP_JOB_2_FRAMES ] used: 0B | peak: 0B | reserved: 1048576B
Error Unity [ ALLOC_TEMP_JOB_4_FRAMES ] used: 0B | peak: 0B | reserved: 2097152B
Error Unity [ ALLOC_TEMP_JOB_ASYNC ] used: 4326745B | peak: 0B | reserved: 7340032B
Error Unity [ ALLOC_DEFAULT ] used: 15634711B | peak: 165212737B | reserved: 15974431B
Error Unity [ ALLOC_GAMEOBJECT ] used: 820820B | peak: 820952B | reserved: 823005B
Error Unity [ ALLOC_GFX ] used: 777844463B | peak: 777844463B | reserved: 777845964B
Error Unity (Filename: Line: 1449)
它最初下载了一些图像并添加到库中,crashes.Is 因为下载的图像很大?我试图通过使用 webrequest datahandler dispose 方法释放大小,但没有 effect.How 来解决与内存相关的 issues.Any 指南?
Error Unity Could not allocate memory: System out of memory!
Error Unity Trying to allocate: 72192000B with 16 alignment. MemoryLabel: NativeArray
看来你的贴图分辨率很高。此外,它们似乎未压缩。
纹理大小:6000 * 4000 * 4(RGBA) = 96MB
使用更小或压缩的纹理。 最好在将图像上传到 GPU 之前降低图像的分辨率并进行压缩。理想情况下,纹理大小应该是两侧的二次方。这些尺寸如下:2、4、8、16、32、64、128、256、512、1024、2048 或 4096 像素。