atteneder / KtxUnity

Load KTX and Basis Universal textures at runtime
Apache License 2.0
223 stars 42 forks source link

KTX BASIS textures fail to load in IOS builds #33

Closed ASquareDevs closed 3 years ago

ASquareDevs commented 3 years ago

Hi, I'm Jose with A Square, my team is working with BrandXR on the Discovery platform.

I am having issues building to iPhone where I get this issue only in builds, in editor for IOS the ktx and basis textures are loaded and it works, but when I try to build I'm getting this error and the onTextureLoaded action is never called.

I'm getting this in XCode's debug console; image

These are the textures I am trying to load: https://bxrtest.s3.amazonaws.com/KTX+Tests/horse/material0_basecolor.ktx2 https://bxrtest.s3.amazonaws.com/KTX+Tests/mario_transparent.basis

atteneder commented 3 years ago

Thanks for reporting. I'll try to reproduce soon.

atteneder commented 3 years ago

I could reproduce! Will look at it next week.

ASquareDevs commented 3 years ago

I did manage to fix it by setting Xcode's optimization level to smallest when it was set to smallest and fastest. That and the Allocation of the native array had to be set to temp job.

atteneder commented 3 years ago

Great observation! But weird...makes me think it's some imprecision only showing up in certain configurations (architecture-optimization level combination)

blackbird-91 commented 3 years ago

@atteneder I'm having a similar issue with crashes on iOS builds with ktx2 files. It works fine in the editor and on iOS build only when deep profiling is enabled in build settings. When trying to create a release build or one without deep profiling enabled, it crashes when trying to load an object with ktx2 texture.

The above suggestion to set the optimization level to smallest did not work in my case.

Unity version: 2020.2.7f1 GLTFast version: 3.0.2 KTXUnity version: 1.0.0 Device tested: iPhone 11 running 13.2.3 Screen Shot 2021-03-10 at 12 45 47 AM

atteneder commented 3 years ago

@blackbird-91 Thanks for reporting.

Might be related to #11 on Android. I'll try to have a look soon.

blackbird-91 commented 3 years ago

@blackbird-91 Thanks for reporting.

Might be related to #11 on Android. I'll try to have a look soon.

@atteneder Thanks for following up and directing me to the issue. Based on the thread you linked, a previous version of both gltfast and KTXUnity where you use coroutines instead of async await should technically work in the iOS release builds. But that did not fix the issue for me, I tried going back upto gltfast version 1.0.1 and ktxunity v0.8. All of them crashed.

Some more specs I missed in my previous post - 15" Macbook Pro (2016) OSX version: Big Sur 11.1 XCode version: 12.4(12D4e)

Please let me know if you got any updates regarding this issue.

ruben-ivre commented 3 years ago

Any news on this issue? we tried everything we could but we can't get it working with the sample project. We tried the XCode optimization and the allocation fix, but no luck. We tried with latest version here and with the forked version from @mmusial too, which fixed Android for us.

mmusial commented 3 years ago

Any news on this issue? we tried everything we could but we can't get it working with the sample project. We tried the XCode optimization and the allocation fix, but no luck. We tried with latest version here and with the forked version from @mmusial too, which fixed Android for us.

For me using my "coroutine branch" (details: #11) resolved all crashing on both Android and iOS. I'm using ETC1S (RGB) and UASTC (RGB/RGBA), both as KTX2 files. What type of texture you are trying to load?

atteneder commented 3 years ago

Sorry about the inconvenience, but unfortunately no. It'll take some more weeks for me to have a look since I'm on paternity leave as well.

ruben-ivre commented 3 years ago

For me using my "coroutine branch" (details: #11) resolved all crashing on both Android and iOS. I'm using ETC1S (RGB) and UASTC (RGB/RGBA), both as KTX2 files. What type of texture you are trying to load?

We tried with your branch too, as we use it to solve our Android issues, but iOS is still failing. We are using lz compressed BASIS format in KTX container (we use the ktxtool with --bcmp flag).

mmusial commented 3 years ago

For me using my "coroutine branch" (details: #11) resolved all crashing on both Android and iOS. I'm using ETC1S (RGB) and UASTC (RGB/RGBA), both as KTX2 files. What type of texture you are trying to load?

We tried with your branch too, as we use it to solve our Android issues, but iOS is still failing. We are using lz compressed BASIS format in KTX container (we use the ktxtool with --bcmp flag).

Below are my arguments for toktx that works for me (Android, iOS, PC[Win64]):

toktx --srgb --lower_left_maps_to_s0t0 --genmipmap --bcmp --clevel 3 <output.ktx2> <input.png>
toktx --srgb --lower_left_maps_to_s0t0 --genmipmap --uastc 3 --zcmp 10 <output.ktx2> <input.png>
ruben-ivre commented 3 years ago

Thank you very much @mmusial, adding the --genmipmap parameter did the trick, I owe you twice, one for the Android fix and another for this one. Adding the mipmaps makes the file a little bit bigger, but we can live with that.

mmusial commented 3 years ago

Thank you very much @mmusial, adding the --genmipmap parameter did the trick, I owe you twice, one for the Android fix and another for this one. Adding the mipmaps makes the file a little bit bigger, but we can live with that.

I'm glad I could help :)

atteneder commented 3 years ago

I found two bugs in the C binding that are likely the real reason for those crashes. I just tested KtxUnity 1.1.0 successfully on iOS (arm64).