加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Android:Buffer not large enough for pixels

(2013-05-27 15:59:18)
分类: JAVA-Android
这几天一直纠结于一个svc解码播放的Android程序的问题,问了不少人,搜了很多,纠结了差不多两三个星期依然没有解决。今天沉下来好好看了一下logcat,赫然发现我下的数个svc播放程序的问题竟然出奇一致:

05-27 07:53:40.389: D/AndroidRuntime(1173): Shutting down VM
05-27 07:53:40.389: W/dalvikvm(1173): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-27 07:53:40.459: E/AndroidRuntime(1173): FATAL EXCEPTION: main
05-27 07:53:40.459: E/AndroidRuntime(1173): java.lang.RuntimeException: Buffer not large enough for pixels
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.graphics.Bitmap.copyPixelsFromBuffer(Bitmap.java:417)
05-27 07:53:40.459: E/AndroidRuntime(1173): at smu.android.svc.SVCVideoView.onDraw(SVCVideoView.java:86)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.View.draw(View.java:13712)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.View.draw(View.java:13596)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.View.draw(View.java:13594)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.View.draw(View.java:13594)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.view.View.draw(View.java:13715)
05-27 07:53:40.459: E/AndroidRuntime(1173): at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-27 07:53:40.459: E/AndroidRuntime(1173): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)

于是对中间标红的错误google,终于在https://code.google.com/p/mapsforge/issues/detail?id=370里找到了问题描述。我将原网页中有用信息复制如下:


What steps will reproduce the problem?
1. Install advanced map viewer on android 4.2
2. Run App and open a map. 
3. See exception

What is the expected output? What do you see instead?
should work, but see exception:
E/AndroidRuntime( 3178): FATAL EXCEPTION: MapWorker
E/AndroidRuntime( 3178): java.lang.RuntimeException: Buffer not large enough for pixels
E/AndroidRuntime( 3178):        at android.graphics.Bitmap.copyPixelsToBuffer(Bi tmap.java:381)
E/AndroidRuntime( 3178):        at org.mapsforge.android.maps.mapgenerator.InMemoryTileCache.put(InMemoryTileCache.java:142)E/AndroidRuntime( 3178):        at org.mapsforge.android.maps.mapgenerator.MapWorker.doWork(MapWorker.jaa:77)
E/AndroidRuntime( 3178):        at org.mapsforge.android.maps.PausableThread.run(PausableThread.java:94)
W/ActivityManager(  390):   Force finishing activity org.mapsforge.applications.android.advancedmapviewer/.AdvancedMapViewer


What version of the product are you using? On what operating system?
0.3.0

Please provide any additional information below.
running on a galaxy nexus with 4.2

Nov 14, 2012
#1 Niklas.S...@gmail.com

I can reproduce this on a Nexus 7 with Android 4.2 debugging shows that Android writes 4 bytes per pixel in copyPixelsToBuffer even though the Bitmap uses Config.RGB565 which according to the docs should be 2 bytes per pixel. Setting the Tile.BYTES_PER_PIXEL to 4 stops the crashing but there are weird artefacts while scrolling (like all tiles are the same).
Nov 15, 2012
#2 Niklas.S...@gmail.com

So after further debugging it turns out that prior to 4.2 copyPixelsFromBuffer() did not advance buffer.position() however it does now. So we need to do a this.byteBuffer.rewind() before calling copyPixelsToBuffer() in InMemoryTileCache.java. I've tried adding it in the online source editor which created  Issue #374 . For reference I've attached the patch here too.
https://ssl.gstatic.com/codesite/ph/images/paperclip.gifnot large enough for pixels" TITLE="Android:Buffer not large enough for pixels" /> InMemoryTileCache.java.patch 
488 bytes   View   Download
Nov 16, 2012
#3 applanta...@gmail.com

I can confirm this issue, it even happens on the 4.2 emulator, which means it is reproducible without a physical device. 
Also, the patch seems to fix the issue, but I am still testing on other (non 4.2) devices. 
It would be good if other people reported feedback here on this patch, just to make sure it does not cause some other issues.
Nov 18, 2012
Project Member #5 thilo.mu...@gmail.com

This issue was closed by revision r2112.

这是Android4.2的bug,艹。
现在我正安装低版本的android以测试程序。

对于这个bug的解决方法不是下载低版本的android程序,修改方法如下:
graphics/java/android/graphics/Bitmap.java
@@ -413,6 +413,11 @@ public void copyPixelsFromBuffer(Buffer src) {
         }
 
         nativeCopyPixelsFromBuffer(mNativeBitmap, src);
+
       // now update the buffer's position
       int position src.position();
       position += bitmapBytes >> shift;
       src.position(position);
     }
 
     /**

from: https://github.com/android/platform_frameworks_base/commit/55adc145d460be4b21de0d77be1f6076c3591e3c#graphics/java/android/graphics/Bitmap.java

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有