Page MenuHomePhabricator

OutOfMemory condition in Image Gallery results in an unhelpful 'Could not draw the image' error.
Closed, ResolvedPublic

Description

Checked 2.0.102-alpha-2015-06-09 on GT-P7510(tablet 4.0.4).

Found in articles - 'Claude Monet' and 'Camille Pisarro'.
Flipping through the images in Image Gallery, a warning is displayed(quite often) - 'Could not draw the image'. Sometime the warning sticks, even if another viewable image is displayed.

Screenshot_2015-06-10-14-05-58.jpg (1×800 px, 1 MB)

Screenshot_2015-06-10-14-03-08.jpg (1×800 px, 63 KB)

Note: does not happen in iOS.

Event Timeline

Etonkovidova raised the priority of this task from to Needs Triage.
Etonkovidova updated the task description. (Show Details)
Etonkovidova subscribed.
Dbrant renamed this task from Image Gallery: the warning is displayed 'Could not draw the image' to OutOfMemory condition in Image Gallery results in an unhelpful 'Could not draw the image' error..Jun 26 2015, 2:17 PM
Dbrant triaged this task as High priority.
Dbrant set Security to None.
Dbrant moved this task from Needs Triage to Bug Backlog on the Wikipedia-Android-App-Backlog board.

+1, this happened to me on my Note II (which I think has big memory) but I'm not sure on the repro steps yet. Once I started getting it though, I was able to keep getting it by rotating the phone while in the gallery.

unnamed (2).png (1×703 px, 47 KB)

Screenshot_2015-07-17-22-14-36.png (1×720 px, 791 KB)

Screenshots are from The Rime of the Ancient Mariner article.

The "could not draw" issue is quite reproducible on the API 15 emulator[0]:

  1. Go to the Cleveland Bay article.
  2. Tap the lead image.

If fortunate, errors express as "could not draw" messages. If unfortunate, as a crash[1]. Maybe can add a memory profile to the app to figure out what image sizes to request or allow the user to download full resolution but not view it?

[0]

2015-08-03-20-28-06-395460416.png (1×1 px, 134 KB)

[1]

                     V  https://en.m.wikipedia.org/w/api.php?action=query&format=json&titles=File%3ACleveland%2C%20EvThaer%2C%20Celebrity.JPG&continue=&prop=imageinfo&iiprop=
                        url%7Cdimensions%7Cmime%7Cextmetadata&iiurlwidth=1280
GalleryItemFragment  D  Loading image from url: https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Brewster_park_drag_1887.jpg/1280px-Brewster_park_drag_1887.jpg
           dalvikvm  D  GC_FOR_ALLOC freed 913K, 12% free 21817K/24711K, paused 4ms
      dalvikvm-heap  I  Grow heap (frag case) to 22.823MB for 1536012-byte allocation
           dalvikvm  D  GC_FOR_ALLOC freed 10K, 12% free 23307K/26247K, paused 3ms
GalleryItemFragment  D  Loading image from url: https://upload.wikimedia.org/wikipedia/commons/thumb/9/9e/2007_Cleveland_Bays_2.JPG/1280px-2007_Cleveland_Bays_2.JPG
           dalvikvm  D  GC_FOR_ALLOC freed 159K, 12% free 23358K/26247K, paused 4ms
      dalvikvm-heap  I  Grow heap (frag case) to 27.032MB for 4372492-byte allocation
           dalvikvm  D  GC_FOR_ALLOC freed 0K, 10% free 27628K/30535K, paused 3ms
                     D  GC_CONCURRENT freed 172K, 10% free 27678K/30535K, paused 0ms+1ms
                     D  GC_FOR_ALLOC freed 208K, 10% free 27760K/30535K, paused 11ms
      dalvikvm-heap  I  Forcing collection of SoftReferences for 4096012-byte allocation
           dalvikvm  D  GC_BEFORE_OOM freed 31K, 10% free 27729K/30535K, paused 5ms
      dalvikvm-heap  E  Out of memory on a 4096012-byte allocation.
           dalvikvm  I  "Picasso-/wikipedia/commons/thumb/9/9e/2007_Cleveland_Bays_2.JPG/1280px-2007_Cleveland_Bays_2.JPG" prio=5 tid=34 RUNNABLE
                     I    | group="main" sCount=0 dsCount=0 obj=0xb5c45d20 self=0xa2fa408
                     I    | sysTid=4040 nice=10 sched=3/0 cgrp=[fopen-error:2] handle=170298304
                     I    | schedstat=( 0 0 0 ) utm=10 stm=4 core=0
                     I    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
                     I    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
                     I    at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:142)
                     I    at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
                     I    at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
                     I    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
                     I    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
                     I    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
                     I    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
                     I    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
                     I    at java.lang.Thread.run(Thread.java:856)
                     I    at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:394)
               skia  D  --- decoder->decode returned false
GalleryItemFragment  D  Loading image from url: https://upload.wikimedia.org/wikipedia/commons/4/42/Cleveland%2C_EvThaer%2C_Celebrity.JPG
           dalvikvm  D  GC_FOR_ALLOC freed 1136K, 10% free 27693K/30535K, paused 3ms
      dalvikvm-heap  I  Forcing collection of SoftReferences for 4577996-byte allocation
           dalvikvm  D  GC_BEFORE_OOM freed 0K, 10% free 27693K/30535K, paused 0ms
      dalvikvm-heap  E  Out of memory on a 4577996-byte allocation.
           dalvikvm  I  "Picasso-/wikipedia/commons/4/42/Cleveland,_EvThaer,_Celebrity.JPG" prio=5 tid=34 RUNNABLE
                     I    | group="main" sCount=0 dsCount=0 obj=0xb5c45d20 self=0xa2fa408
                     I    | sysTid=4040 nice=10 sched=3/0 cgrp=[fopen-error:2] handle=170298304
                     I    | schedstat=( 0 0 0 ) utm=12 stm=6 core=0
                     I    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
                     I    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
                     I    at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:142)
                     I    at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
                     I    at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
                     I    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
                     I    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
                     I    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
                     I    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
                     I    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
                     I    at java.lang.Thread.run(Thread.java:856)
                     I    at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:394)
               skia  D  --- decoder->decode returned false

[2]

               dalvikvm  D  GC_CONCURRENT freed 3740K, 23% free 19090K/24519K, paused 0ms+1ms
                ApiTask  V  https://en.m.wikipedia.org/w/api.php?action=query&format=json&titles=File%3A%E5%9B%BD%E5%AE%B6%E6%B8%B8%E6%B3%B3%E4%B8%AD%E5%BF%83%E5%A4%9C%E6%99%AF.j
                            pg&continue=&prop=imageinfo&iiprop=url%7Cdimensions%7Cmime%7Cextmetadata&iiurlwidth=1280
    GalleryItemFragment  D  Loading image from url: https://upload.wikimedia.org/wikipedia/commons/4/41/USS_Maddox_%28DD-731%29.jpg
pedia.page.PageActivity  D  unregisterBus():972: Unregistered bus.
               dalvikvm  D  GC_FOR_ALLOC freed 1056K, 25% free 18447K/24519K, paused 3ms
                         D  GC_CONCURRENT freed 313K, 18% free 20181K/24519K, paused 0ms+1ms
    GalleryItemFragment  D  Loading image from url: https://upload.wikimedia.org/wikipedia/commons/c/ca/Cleveland_Bay_hw_crop.jpg
               dalvikvm  D  GC_FOR_ALLOC freed 44K, 18% free 20173K/24519K, paused 8ms
          dalvikvm-heap  I  Grow heap (frag case) to 21.216MB for 1536012-byte allocation
               dalvikvm  D  GC_FOR_ALLOC freed <1K, 17% free 21672K/26055K, paused 3ms
    GalleryItemFragment  D  Loading image from url: https://upload.wikimedia.org/wikipedia/commons/thumb/3/3d/%E5%9B%BD%E5%AE%B6%E6%B8%B8%E6%B3%B3%E4%B8%AD%E5%BF%83%E5%A4%9C%E6%9
                            9%AF.jpg/1280px-%E5%9B%BD%E5%AE%B6%E6%B8%B8%E6%B3%B3%E4%B8%AD%E5%BF%83%E5%A4%9C%E6%99%AF.jpg
               dalvikvm  D  GC_FOR_ALLOC freed 1386K, 21% free 20668K/26055K, paused 0ms
          dalvikvm-heap  I  Grow heap (frag case) to 21.797MB for 1637548-byte allocation
               dalvikvm  D  GC_FOR_ALLOC freed 0K, 20% free 22267K/27655K, paused 2ms
                         D  GC_FOR_ALLOC freed 50K, 20% free 22308K/27655K, paused 2ms
          dalvikvm-heap  I  Grow heap (frag case) to 25.446MB for 3783692-byte allocation
               dalvikvm  D  GC_CONCURRENT freed <1K, 18% free 26003K/31367K, paused 0ms+0ms
              Analytics  D  GalleryFunnel: Sending event, event_action = close, event_pageTitle = Main Page, event_imageTitle = File:Cleveland Bay hw crop.jpg
pedia.page.PageActivity  D  registerBus():966: Registered bus.
              Wikipedia  D  Link clicked was /wiki/Cleveland_Bay
               dalvikvm  D  GC_FOR_ALLOC freed 3713K, 26% free 23442K/31367K, paused 4ms
                         D  GC_FOR_ALLOC freed 4K, 22% free 24717K/31367K, paused 3ms
          dalvikvm-heap  I  Forcing collection of SoftReferences for 2949132-byte allocation
               dalvikvm  D  GC_BEFORE_OOM freed 31K, 22% free 24686K/31367K, paused 0ms
          dalvikvm-heap  E  Out of memory on a 2949132-byte allocation.
               dalvikvm  I  "main" prio=5 tid=1 RUNNABLE
                         I    | group="main" sCount=0 dsCount=0 obj=0xb512f3a8 self=0x9f33318
                         I    | sysTid=3872 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-1207563136
                         I    | schedstat=( 0 0 0 ) utm=108 stm=18 core=0
                         I    at android.graphics.Bitmap.nativeCreate(Native Method)
                         I    at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
                         I    at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
                         I    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
                         I    at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
                         I    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
                         I    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
                         I    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
                         I    at android.content.res.Resources.loadDrawable(Resources.java:1935)
                         I    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
                         I    at android.widget.ImageView.<init>(ImageView.java:119)
                         I    at android.widget.ImageView.<init>(ImageView.java:109)
                         I    at java.lang.reflect.Constructor.constructNative(Native Method)
                         I    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                         I    at android.view.LayoutInflater.createView(LayoutInflater.java:586)
                         I    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                         I    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
                         I    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
                         I    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
                         I    at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
                         I    at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
                         I    at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
                         I    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                         I    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                         I    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                         I    at org.wikipedia.page.linkpreview.LinkPreviewDialog.onCreateView(LinkPreviewDialog.java:80)
                         I    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
                         I    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
                         I    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
                         I    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
                         I    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
                         I    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
                         I    at android.os.Handler.handleCallback(Handler.java:605)
                         I    at android.os.Handler.dispatchMessage(Handler.java:92)
                         I    at android.os.Looper.loop(Looper.java:137)
                         I    at android.app.ActivityThread.main(ActivityThread.java:4424)
                         I    at java.lang.reflect.Method.invokeNative(Native Method)
                         I    at java.lang.reflect.Method.invoke(Method.java:511)
                         I    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                         I    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                         I    at dalvik.system.NativeStart.main(Native Method)
         AndroidRuntime  D  Shutting down VM
               dalvikvm  W  threadid=1: thread exiting with uncaught exception (group=0xb512e180)
                   ACRA  E  ACRA caught a InflateException exception for org.wikipedia.dev. Building report.
                         D  Using default Mail Report Fields
                         I  READ_LOGS not allowed. ACRA will not include LogCat and DropBox data.
                         D  Writing crash report file 1435922231000.stacktrace.
                         D  Waiting for Toast + worker...
                         D  About to create DIALOG from #handleException
                         D  Creating Dialog for 1435922231000.stacktrace
                         D  Wait for Toast + worker ended. Kill Application ? true
                         E  org.wikipedia.dev fatal error : Binary XML file line #76: Error inflating class <unknown>
                         E  android.view.InflateException: Binary XML file line #76: Error inflating class <unknown>
                         E      at android.view.LayoutInflater.createView(LayoutInflater.java:606)
                         E      at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
                         E      at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
                         E      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
                         E      at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
                         E      at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
                         E      at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
                         E      at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
                         E      at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                         E      at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                         E      at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                         E      at org.wikipedia.page.linkpreview.LinkPreviewDialog.onCreateView(LinkPreviewDialog.java:80)
                         E      at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
                         E      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
                         E      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
                         E      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
                         E      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
                         E      at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
                         E      at android.os.Handler.handleCallback(Handler.java:605)
                         E      at android.os.Handler.dispatchMessage(Handler.java:92)
                         E      at android.os.Looper.loop(Looper.java:137)
                         E      at android.app.ActivityThread.main(ActivityThread.java:4424)
                         E      at java.lang.reflect.Method.invokeNative(Native Method)
                         E      at java.lang.reflect.Method.invoke(Method.java:511)
                         E      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                         E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                         E      at dalvik.system.NativeStart.main(Native Method)
                         E  Caused by: java.lang.reflect.InvocationTargetException
                         E      at java.lang.reflect.Constructor.constructNative(Native Method)
                         E      at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                         E      at android.view.LayoutInflater.createView(LayoutInflater.java:586)
                         E      ... 26 more
                         E  Caused by: java.lang.OutOfMemoryError
                         E      at android.graphics.Bitmap.nativeCreate(Native Method)
                         E      at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
                         E      at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
                         E      at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
                         E      at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
                         E      at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
                         E      at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
                         E      at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
                         E      at android.content.res.Resources.loadDrawable(Resources.java:1935)
                         E      at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
                         E      at android.widget.ImageView.<init>(ImageView.java:119)
                         E      at android.widget.ImageView.<init>(ImageView.java:109)
                         E      ... 29 more
                         I  Finishing the last Activity prior to killing the Process
                         I  Finished class org.wikipedia.page.gallery.GalleryActivity
                Process  I  Sending signal. PID: 3872 SIG: 9

The same device cannot manage reloading the banana article which isn't that long :/

I recommend this issue be tackled soon. It appears often in even casual usage and is quite easy to repro on the stock AOSP ICS emulator.

It seems like there are actually two issues here:
(1) That this happens (a lot) on older devices/Androids, and we should find ways to prevent it from happening, and
(2) That it should be handled more gracefully when it does happen.

We've been thinking along the lines of the broader issue (1) -- see T109128, for example -- but the task description seems to go more to the narrower issue (2). Does this task encompass both? If so, what are the acceptance criteria for (2) -- i.e., what should happen when the image can't be displayed?

There are around 500 _crashes_ tracked so far but caught OOM errors are likely causing a poor non-crash experience on a many sessions untracked.

https://rink.hockeyapp.net/manage/apps/226649/crashes/search?per_page=50&query=reason%3Ajava.lang.OutOfMemoryError&type=groups

This has been fixed on the build 2.1.142 released today. Tested on ZTE Android 5.1.

Dbrant claimed this task.