Hey there,
when loading large images (5000x5000 pixels), and calling GetPixels on them, it crashes on android. This is a minimal example…
void Start()
{
var path = Path.Combine(Application.persistentDataPath, "test.png");
byte[] fileData = File.ReadAllBytes(path);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); // auto-resize the texture dimensions.
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
var colors = tex.GetPixels();
Debug.Log(colors.Length);
}
}
After clicking four times on the screen, the app crashes. I know the images are large, but is that usual?
Furthermore, how can I catch the crash and notify the user that the image is to large? Maybe it has something to do with the device hardware, so but I don’t know the limit for texture on phones. Also I would like to support at least 5000x5000 pixels if possible.
Here is a snippet of the logcat:
Version '2021.3.4f1 (cb45f9cae8b7)', Build type 'Release', Scripting Backend 'mono', CPU 'armeabi-v7a'
Build fingerprint: 'samsung/beyond1lteeea/beyond1:11/RP1A.200720.012/G973FXXU9EUA4:user/release-keys'
Revision: '26'
ABI: 'arm'
Timestamp: 2022-07-05 16:51:15+0200
pid: 25813, tid: 26042, name: UnityMain >>> com.DefaultCompany.TextureCrash <<<
uid: 10316
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
Cause: null pointer dereference
r0 9b230020 r1 00000020 r2 00000010 r3 00000010
r4 b5e91ec8 r5 b62eb384 r6 b62eb390 r7 000004e2
r8 00000004 r9 b62eb310 r10 00001388 r11 b62eb358
ip 00000020 sp b62eb308 lr 000004e1 pc b53f7ad0
managed backtrace:
#00 (wrapper managed-to-native) UnityEngine.Texture2D:GetPixels (UnityEngine.Texture2D,int,int,int,int,int)
#01 UnityEngine.Texture2D:GetPixels (int) <0xaf>
#02 UnityEngine.Texture2D:GetPixels () <0x17>
#03 Test:Update () <0x2f>
#04 (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
at libunity.0x6acad0(Native Method)
Help would be really apprechiated!