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

Help! GifDrawable memory issue - EGL_BAD_SURFACE #67

Closed
Deminem opened this issue Jul 1, 2014 · 2 comments
Closed

Help! GifDrawable memory issue - EGL_BAD_SURFACE #67

Deminem opened this issue Jul 1, 2014 · 2 comments
Labels

Comments

@Deminem
Copy link

Deminem commented Jul 1, 2014

I have 3 x 8 grid which initially display images as ".png". Once user tap on any particular item in the grid, the animated ".gif" replace the placeholder image ".png" and the previous selected item reset to it's original state ".png". The hardware acceleration is also enabled for this particular activity as well.

I am getting the EGL_BAD_SURFACE error after tapping on different items in continuous order for more than 1 or 2 minutes. Please see the code snippet and exception below.

Can you please advice that how can I eliminate/reduce the memory footprint attached to GifDrawable.

Grid Loading items

viewHolder.gifImageView.setImageResource(animoticonItem.getPlaceHolderIconResc());

Item Selection

// Reset the last selection.
if (currentSelectedVHItem != null && currentSelectedItemIndex != position) {
      if (currentSelectedVHItem.gifImageView != null) {

         Animoticon animoticon = currentSelectedVHItem.animoticon;
         currentSelectedVHItem.gifImageView.setImageResource(animoticon.getPlaceHolderIconResc());
         currentSelectedVHItem = null;
      } 
}

// New item selection
ViewHolderItem itemHolder = (ViewHolderItem)parentView.getTag();
if (itemHolder != null && itemHolder.gifImageView != null) {

       // show the small animated animoticon
       GifDrawable drawable = new GifDrawable(mContext.getAssets(), selectedItem.getAnimatedGifSmallPath());
       drawable.clearColorFilter();
       drawable.setSpeed(1.0f);

       // set animated gif
       itemHolder.gifImageView.setImageDrawable(drawable);
}

// keep the references
currentSelectedVHItem = itemHolder;

Everything works well, if you keep tapping on different items for 1 or 2 minutes. But then it start sending the memory warnings and finally the below error, after that UI freezes and user have to kill the app.

07-01 15:28:35.903: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:28:36.118: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:28:36.123: W/HardwareRenderer(11948): EGL error: EGL_BAD_SURFACE
07-01 15:28:36.138: W/HardwareRenderer(11948): Mountain View, we've had a problem here. Switching back to software rendering.
07-01 15:28:36.513: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:28:51.103: D/dalvikvm(11948): GC_FOR_ALLOC freed 11606K, 26% free 40634K/54604K, paused 22ms, total 22ms
07-01 15:28:51.118: I/dalvikvm-heap(11948): Grow heap (frag case) to 46.496MB for 5670016-byte allocation
07-01 15:28:51.138: D/dalvikvm(11948): GC_FOR_ALLOC freed 3K, 24% free 46168K/60144K, paused 24ms, total 24ms
07-01 15:28:51.293: D/dalvikvm(11948): GC_FOR_ALLOC freed 3192K, 29% free 42981K/60144K, paused 22ms, total 22ms
07-01 15:28:51.308: I/dalvikvm-heap(11948): Grow heap (frag case) to 48.012MB for 4856416-byte allocation
07-01 15:28:51.333: D/dalvikvm(11948): GC_FOR_ALLOC freed 0K, 27% free 47724K/64888K, paused 24ms, total 24ms
07-01 15:28:51.708: D/AbsListView(11948): onDetachedFromWindow
07-01 15:28:51.708: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:28:52.358: D/AbsListView(11948): Get MotionRecognitionManager
07-01 15:28:52.873: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:28:52.873: I/Choreographer(11948): Skipped 31 frames!  The application may be doing too much work on its main thread.
07-01 15:28:52.913: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:28:52.938: D/dalvikvm(11948): GC_FOR_ALLOC freed 11610K, 26% free 39065K/52140K, paused 20ms, total 20ms
07-01 15:28:52.948: I/dalvikvm-heap(11948): Grow heap (frag case) to 44.187MB for 4856416-byte allocation
07-01 15:28:52.963: D/dalvikvm(11948): GC_FOR_ALLOC freed 2K, 23% free 43805K/56884K, paused 16ms, total 16ms
07-01 15:28:53.103: D/dalvikvm(11948): GC_FOR_ALLOC freed 27K, 24% free 43777K/56884K, paused 17ms, total 17ms
07-01 15:28:53.113: I/dalvikvm-heap(11948): Grow heap (frag case) to 49.565MB for 5670016-byte allocation
07-01 15:28:53.133: D/dalvikvm(11948): GC_FOR_ALLOC freed 0K, 22% free 49314K/62424K, paused 18ms, total 18ms
07-01 15:30:04.333: D/dalvikvm(11948): GC_FOR_ALLOC freed 0K, 27% free 46187K/62424K, paused 18ms, total 18ms
07-01 15:30:04.708: D/AbsListView(11948): onDetachedFromWindow
07-01 15:30:04.708: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:30:05.278: D/AbsListView(11948): Get MotionRecognitionManager
07-01 15:30:05.793: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:30:05.793: I/Choreographer(11948): Skipped 31 frames!  The application may be doing too much work on its main thread.
07-01 15:30:05.813: D/AbsListView(11948): unregisterIRListener() is called 
07-01 15:30:05.838: D/dalvikvm(11948): GC_FOR_ALLOC freed 11591K, 31% free 36025K/52140K, paused 19ms, total 20ms
07-01 15:30:05.848: I/dalvikvm-heap(11948): Grow heap (frag case) to 41.219MB for 4856416-byte allocation
07-01 15:30:05.868: D/dalvikvm(11948): GC_FOR_ALLOC freed 6K, 29% free 40761K/56884K, paused 17ms, total 17ms
07-01 15:30:05.878: E/Surface(11948): dequeueBuffer failed (Unknown error 2147483646)
07-01 15:30:05.883: E/ViewRootImpl(11948): Could not lock surface
07-01 15:30:05.883: E/ViewRootImpl(11948): java.lang.IllegalArgumentException
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.Surface.nativeLockCanvas(Native Method)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.Surface.lockCanvas(Surface.java:253)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2721)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.ViewRootImpl.draw(ViewRootImpl.java:2695)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2533)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2107)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1200)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6388)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.Choreographer.doCallbacks(Choreographer.java:603)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.Choreographer.doFrame(Choreographer.java:573)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.os.Handler.handleCallback(Handler.java:733)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.os.Handler.dispatchMessage(Handler.java:95)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.os.Looper.loop(Looper.java:157)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at android.app.ActivityThread.main(ActivityThread.java:5293)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at java.lang.reflect.Method.invokeNative(Native Method)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at java.lang.reflect.Method.invoke(Method.java:515)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
07-01 15:30:05.883: E/ViewRootImpl(11948):  at dalvik.system.NativeStart.main(Native Method)
@Deminem Deminem changed the title EGL_BAD_SURFACE memory issue Help! EGL_BAD_SURFACE memory issue Jul 1, 2014
@Deminem Deminem changed the title Help! EGL_BAD_SURFACE memory issue Help! GifDrawable memory issue - EGL_BAD_SURFACE Jul 1, 2014
@koral--
Copy link
Owner

koral-- commented Jul 1, 2014

I wrote a post about memory recently, see #66. Additionally with the latest snapshot GifDrawable instances can be reused, see last post in #30.
I've found this: https://code.google.com/p/android/issues/detail?id=63738 about EGL_BAD_SURFACE. Does it happen on android 4.4.x in your case?

@Deminem
Copy link
Author

Deminem commented Jul 2, 2014

Thanks for your feedback. I have seen both mentioned post and using the latest library snapshot, I confirm that library reuse GifDrawable frame buffer for certain cases but not all the time. Please see the attached screenshot.

gifdrawable

However, I have tweaked different areas to reduce the memory footprint attached with GifDrawable and also recycle the dangling memory references on item selection. Now it keep the creation of new GifDrawable instances at minimum and looks good.

Yes, I was testing on Kitkat 4.4.2 and confirm that EGL_BAD_SURFACE specific to it. Thanks for your help.

@koral-- koral-- closed this as completed Jul 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants