Android: NC - Android client crashes when swiping images during full-img download

Created on 15 Feb 2020  Â·  14Comments  Â·  Source: nextcloud/android

Steps to reproduce

  1. Open image folder and enlarge images. (Switch to full screen slide show)
  2. Swipe left and right
  3. If client offers to download original version of image as no smaller version is stored, do not answer, but swipe to another image. (Also had crashes w/o step 3)
  4. Repeat a couple of times and client crashes

Expected behaviour

Client should discard message, and display next image.

Actual behaviour

Client crashes, displays "cause of error" and dies. Error report says "out of memory".
Ram never drops below 40% ~ 1.7 Gb free. (checked with RAM-monitoring tool)

Environment data

Android version: 6.01

Device model: Lenovo YT3-X90F

Stock or customized system: stock

Nextcloud app version: 3.10.1

Nextcloud server version: 17.0.2

Logs

Client error report

Interesting (IMHO) information marked bold
*** CAUSE OF ERROR ***

java.lang.OutOfMemoryError: Failed to allocate a __44744716 byte__ allocation with __12068672 free bytes__ and 11MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:686)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:633)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:708)
at com.owncloud.android.ui.adapter.DiskLruImageCache.getBitmap(DiskLruImageCache.java:121)
at com.owncloud.android.datamodel.ThumbnailsCacheManager.getBitmapFromDiskCache(ThumbnailsCacheManager.java:225)
at com.owncloud.android.ui.preview.PreviewImageFragment.onStart(PreviewImageFragment.java:254)
at androidx.fragment.app.Fragment.performStart(Fragment.java:2632)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:915)
at androidx.fragment.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManagerImpl.java:713)
at androidx.fragment.app.FragmentManagerImpl.startPendingDeferredFragments(FragmentManagerImpl.java:1325)
at androidx.fragment.app.FragmentManagerImpl.doPendingDeferredStart(FragmentManagerImpl.java:2178)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1703)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:299)
at androidx.fragment.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:259)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager$3.run(ViewPager.java:273)
at androidx.viewpager.widget.ViewPager.completeScroll(ViewPager.java:2005)
at androidx.viewpager.widget.ViewPager.scrollToItem(ViewPager.java:692)
at androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:670)
at androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:631)
at androidx.viewpager.widget.ViewPager.dataSetChanged(ViewPager.java:1086)
at androidx.viewpager.widget.ViewPager$PagerObserver.onChanged(ViewPager.java:3097)
at androidx.viewpager.widget.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:291)
at com.owncloud.android.ui.preview.PreviewImageActivity$DownloadFinishReceiver.onReceive(PreviewImageActivity.java:503)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:881)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5609)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)

*** APP INFORMATION ***
ID: com.nextcloud.client
Version: 30100190
Build flavor: gplay

*** DEVICE INFORMATION ***
Brand: Lenovo
Device: YT3
Model: Lenovo YT3-X90F
Id: MMB29M
Product: YT3_10_row_wifi

*** FIRMWARE ***
SDK: 23
Release: 6.0.1
Incremental: YT3-X90F_USR_S200322_1706140050_WW17_BP_ROW

approved bug

All 14 comments

@tobiasKaminsky I presume we don't down-scale during image decoding? Allocating 44MB can be indeed too much.

Having 2GB or free RAM does not help here - applications have hard limits of how much memory can it allocate, to avoid dodgy apps crippling the whole system.

Hm. From stracktrace it seems that you downloaded an image…
I will have a look how much memory we consume.

indeed from profiler it seems, that it is memory is increasing all the time when swiping through the images.

Here you will find an APK file which you can install in parallel, can you give it a try?
https://github.com/nextcloud/android/pull/5707

After installing the App on the tablet, which had formerly produced the error, I could reproduce the error in the same way as before, however got no detailled crash-report.

What I did: After I had swiped through smaller (around 5 Megs) images with the app working fine, I tried a folder with bigger images (from 8 to 15 MB) and the app crashed repeatedly.

@tobiasKaminsky I presume we don't down-scale during image decoding? Allocating 44MB can be indeed too much.

We do, but according to stack trace it crashes when showing a cached image. And this is at most 80-100kb…

@otto-unnormalverbraucher I tried to reproduce it on an emulator with only 256Mb RAM and one emulator with Android 6.
In both cases it worked without problems… :/
On Android Studio there is a "profiler" where I can see the memory consumption. It went up a bit, but as soon as it reached a certain level, it stayed the same…On 256MB RAM it was ~140Mb.

Maybe this is too much if there are too many other apps running.
Can you test it with opening a bunch of apps and see if you can trigger this earlier?
Can you also test NC app after restart of the phone? If this makes a difference.

I can reproduce it with an old Samsung S5 Neo…
Even with prior downscaling it always crashes at BitmapFactory.decodeStream(…) right now…

I tried to reproduce it last nigh and I run out of internet (lost connection, was late at night, went to sleep) before it happened again, so it might easily be difficult to track.

Can you try the APK in https://github.com/nextcloud/android/pull/5707#issuecomment-604441240?
@StyXman @otto-unnormalverbraucher

Found the time to install and tested with the tablet freshly booted. Images were about 700 to 900K this time. The images came from my server via WLan, but stable and fast connection given.
What I did as test:

  1. Swiped a lot, to make the tablet load a lot of data, then
  2. double-tap a picture to bring it to full size and
  3. immeatiately ignored the "download full version of image" message but
  4. swiped further, then
  5. two or three swipes later taped on OK.
    That sequence repeatedly reproduced the crash

Thanks for testing.
I only tried to get rid of crash when browsing the images, so you can do this:

  • go into a folder with many images
  • make sure they are not downloaded
  • swipe through all of them (without downloading, zooming, etc)

If this works, then we can try to reproduce other scenarios.

Did as you advised. Swiping alone does work for me.
I swiped through hundreds of photos w/o any problem. Tried landscape as well as portrait orientation and all went well.

Nice, this sounds promising :-)

So, what is in addition not working?
Clicking on ok leads to download the file.
Can you try to first download a bunch of files and then swipe through them to see if this is crashing?

I downloaded ~ 50 images and swiped through them with the new APK, but no problems…

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JSoko picture JSoko  Â·  3Comments

daywalk3r666 picture daywalk3r666  Â·  3Comments

AndyScherzinger picture AndyScherzinger  Â·  3Comments

tobiasKaminsky picture tobiasKaminsky  Â·  3Comments

JSoko picture JSoko  Â·  3Comments