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

Fix : android crash when attaching a large size image #7209

Merged
merged 9 commits into from
Jan 25, 2022

Conversation

ahmdshrif
Copy link
Contributor

@ahmdshrif ahmdshrif commented Jan 13, 2022

Details

  • fixe App crashes when attaching a large size image in android chat

Fixed Issues

$ #6836

Tests

  • Verify that no errors appear in the JS console

QA Steps

1- Open app and login
2- Open any chat
3- Tap on + > Add Attachment > Choose from galery
4- Select a very long image
5- Wait a moment
6- Verify that app not crash

  • Verify that no errors appear in the JS console

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Mobile Web

Desktop

iOS

Screen.Recording.2022-01-14.at.8.02.44.PM.mov

Android

Screen.Recording.2021-12-21.at.9.25.56.PM.mov

@github-actions
Copy link
Contributor

github-actions bot commented Jan 13, 2022

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@ahmdshrif ahmdshrif force-pushed the fix/android-update-large-image branch from c107ecf to fcfea51 Compare January 13, 2022 20:30
@ahmdshrif
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@ahmdshrif ahmdshrif marked this pull request as ready for review January 13, 2022 21:00
@ahmdshrif ahmdshrif requested a review from a team as a code owner January 13, 2022 21:00
@botify botify requested review from Jag96 and parasharrajat January 13, 2022 21:00
@MelvinBot MelvinBot removed the request for review from a team January 13, 2022 21:00
@parasharrajat
Copy link
Member

@ahmdshrif Could you please add videos for all platforms? Videos should cover Image zooming.
Also, please update the issue description.
image

Should be
$ https://github.com/Expensify/App/issues/6836

@@ -27,11 +27,14 @@ const propTypes = {
/**
* See https://github.com/react-native-image-picker/react-native-image-picker/#options
* for ImagePicker configuration options
* maxWidth and maxHeight to avoid android crash when with large images
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more details. What is the effect of adding these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more details. What is the effect of adding these?

done,


@ahmdshrif Could you please add videos for all platforms? Videos should cover Image zooming. Also, please update the issue description. image

Should be $ https://github.com/Expensify/App/issues/6836

I update android and ios videos with zoom.
note I only change files with extension .native.js
so it only affects android and ios.
also, this issue is only on android.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the description is still wrong. The template must be saying to add only the link to the issue.

Could you please replace $ GH_LINK with $ https://github.com/Expensify/App/issues/6836

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I change the link,
and describe the changes more.

@ahmdshrif ahmdshrif changed the title add maxwidth and maxheight to image picker Fix : android crash when attaching a large size image Jan 14, 2022
Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I tested it. But results are not favorable. During the proposal review, you said that image quality is not decreased but I see pixilated image. Although, it prevents app crashes but makes the feature literally unusable.

Can you please do some research and share that with us How did you end up deciding the resizing is necessary? I didn't get the answer to this question during the proposal review. We will try to find a solution together.

Also, If resizing is the only way. How can we do that without compromising the image quality? If we can't resize with the same quality, then what do you suggest as an alternative so that we can

  1. Prevent the crash.
  2. User is able to use the feature properly.

@ahmdshrif
Copy link
Contributor Author

ahmdshrif commented Jan 15, 2022

Ok. I tested it. But results are not favorable. During the proposal review, you said that image quality is not decreased but I see pixilated image. Although, it prevents app crashes but makes the feature literally unusable.

@parasharrajat
I mention it will not affect small images .but affect the large image relative to its size.

I think @Jag96 is mentioning in review it's acceptable since it does not affect the small images.

Agreed, and if there isn't any quality degradation for images smaller than the maxHeight/maxWidth values we set then I think that should be fine.

@parasharrajat
Copy link
Member

Ok. Thanks for pointing. It's ok to have resizing. But may be there is a better alternative so that user can still interpret the information that he is sharing.

@ahmdshrif
Copy link
Contributor Author

i also get new solution which adding android:hardwareAccelerated="false to AndroidManifest.xml
it works great without any resizing.

ss.mov

@ahmdshrif
Copy link
Contributor Author

Ok. Thanks for pointing. It's ok to have resizing. But may be there is a better alternative so that user can still interpret the information that he is sharing.

@parasharrajat yes the new solution is working fine without any resizing if you agree I will push it now.

@ahmdshrif
Copy link
Contributor Author

@parasharrajat after debugging I find this error happens in react-native-pan-zoom . when I disable it I can use large images without any issue.

after tracking the native error its comes from android canvas which is used in react-native-pan-zoom .
and the only solution I find for this is to disable android:hardwareAccelerated
https://stackoverflow.com/questions/39111248/canvas-trying-to-draw-too-large-bitmap-when-android-n-display-size-set-larger

so we have 2 solutions now :
The first is to disable android:hardwareAccelerated and I prefer this one and have already pushed it so you can test it.

second :
is resize the image only in react-native -zoom not in the image picker. so the user will have some quality dropping but it can download the image with full quality.

@parasharrajat
Copy link
Member

Thanks, @ahmdshrif. I will check about the usages of hardware acceleration. Although, it seems a small change it affects the whole app. This decision can't be taken alone. But we are getting close. Now you have traced the error to react-native-pan-zoom. We may have better chances of resolving this. Let's see if we can fix this in react-native-pan-zoom or try to get some information on why this crash happened on that lib. I will look into this too.

@ahmdshrif
Copy link
Contributor Author

hi, @parasharrajat is this acceptable quality with resizing?
since resizing from zoom pan (not image picker )to max quality can be like that

Screenshot_1642496550
Screenshot_1642496538

@parasharrajat
Copy link
Member

That works. As said #7209 (comment), this is a big decision and it could affect performance badly.
While zooming in a very large image, we can hit the lag. I have not tested it yet but this is why hardware acceleration is used.

But I will give you a suggestion.

  1. Disable the hardware acceleration on the Image modal screen only. And I think there is an easier way of doing it. It is just a matter of looking.
  2. Conditionally turn the hardware acceleration on-off.

@ahmdshrif
Copy link
Contributor Author

@parasharrajat
this image is resizing with hardware accelerator enabled! just resizing to max possible quality

@parasharrajat
Copy link
Member

I didn't get it. Could you please rephrase it?

@ahmdshrif
Copy link
Contributor Author

@parasharrajat
i mean the screenshote in #7209 (comment) is taken without adding
android:hardwareAccelerated="false"

it's just optimization for the previous resizing code.

@parasharrajat
Copy link
Member

Ok. yeah, it looks good. Let me know when can I test.

@ahmdshrif
Copy link
Contributor Author

@parasharrajat I push the code.
I can't confirm that's a perfect solution but it's working fine

I just redefine the fixed number( maxWidth, maxHeight) by ratio, and again no document for that but the small screen crashes with small dimension numbers, and big screens crash with big numbers for image dimension.
by test I find these ration working with all. without any issue.

also, I get the image from the image picker with full quality and just resize it for image zoom View.
but the user still can download the image with the full quality.

I will add check to resize only if it's android. but what do u think about this?

@Jag96
Copy link
Contributor

Jag96 commented Jan 18, 2022

@ahmdshrif it looks like your commits are not signed, please see https://github.com/Expensify/App/blob/main/CONTRIBUTING.md#begin-coding-your-solution-in-a-pull-request and ensure your commits are signed. If you are unable to sign the commits in this PR please open a new one with signed commits.

@parasharrajat
Copy link
Member

@ahmdshrif Could you please merge the main and test it to see if the app still crashes without your solution? It may be possible it is fixed based on QA team.

@ahmdshrif
Copy link
Contributor Author

@parasharrajat I test the main branch and App still crashes.
Maybe they test on large screen devices or with a small image.

ahmdshrif and others added 8 commits January 19, 2022 22:18
Signed-off-by: AHMED <a.s1171111@gmail.com>
Signed-off-by: AHMED <a.s1171111@gmail.com>
Co-authored-by: Rajat Parashar <parasharrajat@users.noreply.github.com>
Signed-off-by: AHMED <a.s1171111@gmail.com>
Signed-off-by: AHMED <a.s1171111@gmail.com>
Signed-off-by: AHMED <a.s1171111@gmail.com>
Signed-off-by: AHMED <a.s1171111@gmail.com>
Signed-off-by: AHMED <a.s1171111@gmail.com>
@ahmdshrif ahmdshrif force-pushed the fix/android-update-large-image branch from 096c979 to cb2a618 Compare January 19, 2022 20:36
@ahmdshrif
Copy link
Contributor Author

@parasharrajat I rebase with main so you can test with and without my code. also, apply changes we discuss.

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I don't think we need to export maxDimensionsScale to CONST as this is a very specific constant. But leaving this to @Jag96.

cc: @Jag96
🎀 👀 🎀 C+ reviewed

@ahmdshrif
Copy link
Contributor Author

I think to make maxDimensionsScale as const. make code more readable.

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app no longer crashes, so it's technically a pass. But I am not seeing a preview on an older device (Nexus 5X). It shows a tiny zoomed-out version briefly, then disappears altogether., with the following native exception:

W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (580x19734, max=16384x16384)

Any suggestions for resolving this?

AndroidBitmapError.mp4

@parasharrajat
Copy link
Member

I think we should use FastImage and this issue should be resovled. This is already a dependency of the project.

@ahmdshrif
Copy link
Contributor Author

ahmdshrif commented Jan 25, 2022

The app no longer crashes, so it's technically a pass. But I am not seeing a preview on an older device (Nexus 5X). It shows a tiny zoomed-out version briefly, then disappears altogether., with the following native exception:

W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (580x19734, max=16384x16384)

Any suggestions for resolving this?

@Julesssss
for me, I test the app in google play and still crash. also, I test the main before and still crash.
note: you should have a device with a small screen also you should wait some time so it's not crash directly on all devices.

also, this pr solves the issue you talking about. we resize the image to the max size that the device can load.

Screen_Recording_20220125-171257_New.Expensify.mp4

@Julesssss
Copy link
Contributor

Ah okay, good point. I guess we should move the following suggestion into a new issue in that case.

@parasharrajat, what do you think? Should your suggestion be separated?

I think we should use FastImage and this issue should be resovled. This is already a dependency of the project.

@parasharrajat
Copy link
Member

Yeah, we can do that @Julesssss

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the Bitmap too large exception was already occuring. As this PR solves the stated problem I'm going to merge.

@Julesssss Julesssss merged commit 7075d8f into Expensify:main Jan 25, 2022
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @Julesssss in version: 1.1.32-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Feb 1, 2022

🚀 Deployed to production by @roryabraham in version: 1.1.33-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@ahmdshrif ahmdshrif deleted the fix/android-update-large-image branch March 11, 2022 09:05
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

Successfully merging this pull request may close these issues.

5 participants