I'm having trouble to solve a Fatal Exception that is occurring when trying to load multiple .png files from my android persistent data path using Unity Web Request.
The coroutine that does the image loading is this:
IEnumerator DoLoadSpriteFromLocal(string p_loadPath, int p_loadID, T p_object, Action p_callback)
{
string __loadPath = p_loadPath;
#if UNITY_ANDROID
__loadPath = $"file://{__loadPath}";
#endif
UnityWebRequest __uwr = UnityWebRequestTexture.GetTexture(__loadPath);
var __operation = __uwr.SendWebRequest();
float __timer = 0;
while(!__operation.isDone)
{
yield return null;
__timer += Time.deltaTime;
if (__timer >= _timeoutTime)
{
break;
}
}
if (__operation.isDone)
{
if (__uwr.isHttpError || __uwr.isNetworkError)
{
p_callback(false, $"Load sprite failed. \nLoad sprite path: {__loadPath} \nLoad sprite error: \n{__uwr.error}", p_loadID, p_object, null);
}
else
{
Texture2D __texture = DownloadHandlerTexture.GetContent(__uwr);
Sprite __sprite = Sprite.Create(__texture, new Rect(0, 0, __texture.width, __texture.height), new Vector2(0.5f, 0.5f));
p_callback(true, $"Load sprite success. \nLoad sprite path: {__loadPath}", p_loadID, p_object, __sprite);
}
}
else
{
p_callback(false, $"Load sprite timeout. \nLoad sprite path: {__loadPath}", p_loadID, p_object, null);
}
}
To load the images I start one of this coroutine for each one of the image files that I want to load.
Then, after some loading the Android closes the game and point out a Fatal Exception with the following message:
01-20 13:40:00.689: E/AndroidRuntime(24907): FATAL EXCEPTION: UnityMain
01-20 13:40:00.689: E/AndroidRuntime(24907): Process: com.DefaultCompany.IndieWrestler, PID: 24907
01-20 13:40:00.689: E/AndroidRuntime(24907): java.lang.Error: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-20 13:40:00.689: E/AndroidRuntime(24907): Version '2019.4.11f1 (2d9804dddde7)', Build type 'Development', Scripting Backend 'mono', CPU 'armeabi-v7a'
01-20 13:40:00.689: E/AndroidRuntime(24907): Build fingerprint: 'Xiaomi/platina/platina:10/QKQ1.190910.002/V12.0.3.0.QDTMIXM:user/release-keys'
01-20 13:40:00.689: E/AndroidRuntime(24907): Revision: '0'
01-20 13:40:00.689: E/AndroidRuntime(24907): ABI: 'arm'
01-20 13:40:00.689: E/AndroidRuntime(24907): Timestamp: 2021-01-20 13:39:53-0300
01-20 13:40:00.689: E/AndroidRuntime(24907): pid: 24907, tid: 24998, name: UnityGfxDeviceW >>> com.DefaultCompany.IndieWrestler <<<
01-20 13:40:00.689: E/AndroidRuntime(24907): uid: 10540
01-20 13:40:00.689: E/AndroidRuntime(24907): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
01-20 13:40:00.689: E/AndroidRuntime(24907): Cause: null pointer dereference
01-20 13:40:00.689: E/AndroidRuntime(24907): r0 00000000 r1 4def3630 r2 00f42300 r3 00000000
01-20 13:40:00.689: E/AndroidRuntime(24907): r4 4def3610 r5 00000001 r6 00000000 r7 00000000
01-20 13:40:00.689: E/AndroidRuntime(24907): r8 00000000 r9 00000000 r10 000007d0 r11 000007d0
01-20 13:40:00.689: E/AndroidRuntime(24907): ip ed33cc50 sp b7306bb0 lr c1082098 pc ed2e256c
01-20 13:40:00.689: E/AndroidRuntime(24907): backtrace:
01-20 13:40:00.689: E/AndroidRuntime(24907): #00 pc 0005e56c /apex/com.android.runtime/lib/bionic/libc.so (__memcpy_base_a55+244) (BuildId: 18716d52b3e361e6d51e50b6e66c16d5)
01-20 13:40:00.689: E/AndroidRuntime(24907): #01 pc 009f5094 /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (vk::ImageManager::UploadThreaded(vk::ScratchBufferAllocation, dynamic_array&, vk::Image*, vk::ImageData const&, VkExtent3D const&, GraphicsFormat, TextureFormat, TextureColorSpace, int, unsigned int)+500) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #02 pc 009f437c /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (vk::ImageManager::Upload(vk::CommandBuffer*, vk::ScratchBuffer*, vk::Image*, vk::ImageData const&, VkExtent3D const&, GraphicsFormat, TextureFormat, TextureColorSpace, int, unsigned int)+388) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #03 pc 009f419c /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (vk::ImageManager::CreateImage(vk::CommandBuffer*, vk::ScratchBuffer*, TextureDimension, vk::ImageData const&, VkExtent3D const&, GraphicsFormat, TextureFormat, TextureColorSpace, int, unsigned int, VkSampleCountFlagBits, bool)+792) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #04 pc 009a0188 /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (vk::Texture::Create(vk::CommandBuffer*, vk::ScratchBuffer*, TextureID, TextureDimension, vk::ImageData const&, VkExtent3D const&, GraphicsFormat, int, VkSampleCountFlagBits, bool, bool)+460) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #05 pc 009a0980 /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (GfxDeviceVK::UploadTexture2D(TextureID, TextureDimension, unsigned char const*, int, int, int, GraphicsFormat, int, TextureUploadFlags, TextureUsageMode)+264) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #06 pc 0036d34f /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&)+6854) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #07 pc 003724b7 /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (GfxDeviceWorker::RunExt(ThreadedStreamBuffer&)+26) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #08 pc 0037247d /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (GfxDeviceWorker::Run()+96) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #09 pc 0036b647 /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (GfxDeviceWorker::RunGfxDeviceWorker(void*)+2) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #10 pc 007f563f /data/app/com.DefaultCompany.IndieWrestler-cNSHuzzHr165gLQPt0pCOA==/lib/arm/libunity.so (Thread::RunThreadWrapper(void*)+342) (BuildId: b554bd08ed514ed0bf8d653470ba6bfaeed63263)
01-20 13:40:00.689: E/AndroidRuntime(24907): #11 pc 000aa8bb /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+20) (BuildId: 18716d52b3e361e6d51e50b6e66c16d5)
01-20 13:40:00.689: E/AndroidRuntime(24907): #12 pc 000619b3 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30) (BuildId: 18716d52b3e361e6d51e50b6e66c16d5)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libc.__memcpy_base_a55(__memcpy_base_a55:244)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.vk::ImageManager::UploadThreaded(vk::ScratchBufferAllocation, dynamic_array&, vk::Image*, vk::ImageData const&, VkExtent3D const&, GraphicsFormat, TextureFormat, TextureColorSpace, int, unsigned int)(UploadThreaded:500)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.vk::ImageManager::Upload(vk::CommandBuffer*, vk::ScratchBuffer*, vk::Image*, vk::ImageData const&, VkExtent3D const&, GraphicsFormat, TextureFormat, TextureColorSpace, int, unsigned int)(Upload:388)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.vk::ImageManager::CreateImage(vk::CommandBuffer*, vk::ScratchBuffer*, TextureDimension, vk::ImageData const&, VkExtent3D const&, GraphicsFormat, TextureFormat, TextureColorSpace, int, unsigned int, VkSampleCountFlagBits, bool)(CreateImage:792)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.vk::Texture::Create(vk::CommandBuffer*, vk::ScratchBuffer*, TextureID, TextureDimension, vk::ImageData const&, VkExtent3D const&, GraphicsFormat, int, VkSampleCountFlagBits, bool, bool)(Create:460)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.GfxDeviceVK::UploadTexture2D(TextureID, TextureDimension, unsigned char const*, int, int, int, GraphicsFormat, int, TextureUploadFlags, TextureUsageMode)(UploadTexture2D:264)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&)(RunCommand:6854)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.GfxDeviceWorker::RunExt(ThreadedStreamBuffer&)(RunExt:26)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.GfxDeviceWorker::Run()(Run:96)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.GfxDeviceWorker::RunGfxDeviceWorker(void*)(RunGfxDeviceWorker:2)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libunity.Thread::RunThreadWrapper(void*)(RunThreadWrapper:342)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libc.__pthread_start(void*)(__pthread_start:20)
01-20 13:40:00.689: E/AndroidRuntime(24907): at libc.__start_thread(__start_thread:30)
There does not seem to be a pattern to when the Android will show this exception since the point at which he stops the game can vary (some times the game will run without any problems, but in the majority of times it will occur the exception).
I tried to use File.ReadAllBytes but the same exception appears.
If someone have a hint to where is the problem in my game would be of a great help!
↧