Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: (Rare) ANR when using ImageFactory.compress() #335

Open
hansemannn opened this issue Jul 21, 2023 · 6 comments
Open

Android: (Rare) ANR when using ImageFactory.compress() #335

hansemannn opened this issue Jul 21, 2023 · 6 comments

Comments

@hansemannn
Copy link
Contributor

hansemannn commented Jul 21, 2023

In some cases, the compress-API can cause an ANR due to draining memory. The solution should be to either make it fully async (via background thread) or use a different, more stable, compression algorithm. Maybe there are advancements in the Android world since the initial release.

Maybe use Compressor for all compression-related tasks?

ANR log:

main (native):tid=1 systid=10769 
#00 pc 0x86b8c libc.so (syscall + 28)
#01 pc 0x1b092c libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*) + 148)
#02 pc 0x3f8964 libart.so (art::JNI<false>::SetByteArrayRegion(_JNIEnv*, _jbyteArray*, int, int, signed char const*) + 504)
#03 pc 0x3410c0 libhwui.so (SkJavaOutputStream::write(void const*, unsigned long) + 92)
#04 pc 0x55825c libhwui.so (sk_empty_output_buffer(jpeg_compress_struct*) (.llvm.15802703823201869038) + 48)
#05 pc 0x12ac8 libjpeg.so (encode_mcu_huff + 820)
#06 pc 0xdcc0 libjpeg.so (compress_output + 504)
#07 pc 0xb2dc libjpeg.so (jpeg_finish_compress + 312)
#08 pc 0x558e7c libhwui.so (SkJpegEncoder::onEncodeRows(int) + 296)
#09 pc 0x558fa4 libhwui.so (SkJpegEncoder::Encode(SkWStream*, SkPixmap const&, SkJpegEncoder::Options const&) + 112)
#10 pc 0x557ef8 libhwui.so (SkEncodeImage(SkWStream*, SkPixmap const&, SkEncodedImageFormat, int) + 64)
#11 pc 0x36375c libhwui.so (android::Bitmap::compress(SkBitmap const&, android::Bitmap::JavaCompressFormat, int, SkWStream*) + 292)
#12 pc 0x3635a8 libhwui.so (android::Bitmap::compress(android::Bitmap::JavaCompressFormat, int, SkWStream*) + 84)
#13 pc 0x338728 libhwui.so (Bitmap_compress(_JNIEnv*, _jobject*, long, int, int, _jobject*, _jbyteArray*) + 136)
       at android.graphics.Bitmap.nativeCompress(Native method)
       at android.graphics.Bitmap.compress(Bitmap.java:1779)
       at ti.imagefactory.ImageFactoryModule.compress(ImageFactoryModule.java:316)
@m1ga
Copy link
Contributor

m1ga commented Jul 21, 2023

I can check it but do you use a different version/fork of the module?
ImageFactoryModule.java:316 doesn't exist:
https://github.com/tidev/ti.imagefactory/blob/stable/android/src/ti/imagefactory/ImageFactoryModule.java

@m1ga
Copy link
Contributor

m1ga commented Jul 21, 2023

As an alternative:

av.imageview with resize:

m1ga/av.imageview@659890c

av.imageview-android-5.1.0.zip

AvImageview.resizeImage({
	blob: sourceBlob,
	width: 400,
	height: 300
})

AvImageview.addEventListener("complete", function(data) {
	console.log(data.blob.width, data.blob.height)
});

and then you can put that resized blob into the compression

@hansemannn
Copy link
Contributor Author

We use 4.1.1 right now, but I assume the compression didn't change there, yet. We would really prefer a stable API in this module if possible - the Compressor lib really looks promising. What do you think? Maybe I can also do the change

@m1ga
Copy link
Contributor

m1ga commented Jul 21, 2023

No that didn't change, was just wondering if you have a different fork that might do some other work before. I did a test with a backgroundThread already and it works but I just can't get the image back into the app 😄

Compressor looks good to but I think it will have the same issue if you don't put it in a different thread (it has an example at the bottom).
I just wonder what the issue is:
are you compressing a big image to a lower compress jpg? Then even with the other library you could run into memory issues.
Or did you compress and resize an image? Then I saw other posts of using Glide, Picasso or so to load the image as they do it better and resize them and then compress it.

So different ways to go here but a Compressor module would be nice too. It has some open issue (e.g. memory issues zetbaitsu/Compressor#190) and some open PRs like More precise image resolution so perhaps other libraries are more up to date. But shouldn't be that difficult to create it anyways

@hansemannn
Copy link
Contributor Author

It's used to compress an image prior to uploading it.

@m1ga
Copy link
Contributor

m1ga commented Jul 23, 2023

the compressAsync() method #336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants