Texture2D.GetData crashes on Android, but not windows

This code is consistently crashing my android app:

    var familyColors = new Color[7];
    Texture2D texture = GetMyTexture();
    texture.GetData<Color>(familyColors, 0, 7);

It crashes slightly after the call to GetData, so it appears to be putting the monogame engine in a bad state that causes a later crash. It works like a charm in my windows desktop app.

Here’s the tail of the log:

02-16 14:59:54.560 D/Mono (16334): Searching for ‘java_interop_jnienv_set_byte_array_region’.
02-16 14:59:54.561 D/Mono (16334): Probing ‘java_interop_jnienv_set_byte_array_region’.
02-16 14:59:54.561 D/Mono (16334): Found as ‘java_interop_jnienv_set_byte_array_region’.
02-16 14:59:54.564 D/Mono (16334): DllImport searching in: ‘__Internal’ (’(null)’).
02-16 14:59:54.564 D/Mono (16334): Searching for ‘java_interop_jnienv_get_byte_array_region’.
02-16 14:59:54.565 D/Mono (16334): Probing ‘java_interop_jnienv_get_byte_array_region’.
02-16 14:59:54.565 D/Mono (16334): Found as ‘java_interop_jnienv_get_byte_array_region’.
02-16 14:59:54.629 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:54.629 D/Mono (16334): Searching for ‘glGenTextures’.
02-16 14:59:54.630 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:54.630 D/Mono (16334): Searching for ‘glBindTexture’.
02-16 14:59:54.631 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:54.631 D/Mono (16334): Searching for ‘glTexParameteri’.
02-16 14:59:54.634 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:54.634 D/Mono (16334): Searching for ‘glTexImage2D’.
02-16 14:59:54.649 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:54.649 D/Mono (16334): Searching for ‘glPixelStorei’.
02-16 14:59:55.339 D/Mono (16334): DllImport searching in: ‘openal32.dll’ (’./libopenal32.so’).
02-16 14:59:55.339 D/Mono (16334): Searching for ‘alGenBuffers’.
02-16 14:59:55.341 D/Mono (16334): DllImport searching in: ‘openal32.dll’ (’./libopenal32.so’).
02-16 14:59:55.341 D/Mono (16334): Searching for ‘alGetError’.
02-16 14:59:55.359 D/Mono (16334): DllImport searching in: ‘openal32.dll’ (’./libopenal32.so’).
02-16 14:59:55.360 D/Mono (16334): Searching for ‘alBufferData’.
02-16 14:59:55.361 D/Mono (16334): DllImport searching in: ‘openal32.dll’ (’./libopenal32.so’).
02-16 14:59:55.361 D/Mono (16334): Searching for ‘alGetBufferi’.
02-16 14:59:55.447 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:55.447 D/Mono (16334): Searching for ‘glGenFramebuffers’.
02-16 14:59:55.448 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:55.448 D/Mono (16334): Searching for ‘glFramebufferTexture2D’.
02-16 14:59:55.452 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:55.452 D/Mono (16334): Searching for ‘glReadPixels’.
02-16 14:59:55.457 D/Mono (16334): DllImport searching in: ‘libGLESv2.dll’ (’/system/lib/libGLESv2.so’).
02-16 14:59:55.458 D/Mono (16334): Searching for ‘glDeleteFramebuffers’.
02-16 14:59:55.460 F/ (16334): * Assertion at /Users/builder/data/lanes/3511/501e63ce/source/mono/mono/sgen/sgen-alloc.c:384, condition `*p == NULL’ not met
02-16 14:59:55.461 F/libc (16334): Fatal signal 6 (SIGABRT), code -6 in tid 16334 (tafreak.Trapdot)

Texture2D.GetData is not supported in GL ES 2. This came up before in a GitHub issue. What are you using it for specifically? There’s often a better way to do things that does not rely on pulling texture data from the GPU (which is typically very slow).

Yeah, I saw the issue after I posted. I’m using it as a clever way to store palette information without having to create extra files for it. It’s easy to work around. Thanks for the reply!

1 Like

You could extract the data in the build step using a content pipeline extension if you’d like to automate it