close
这几天一直纠结于一个svc解码播放的Android程序的问题,问了不少人,搜了很多,纠结了差不多两三个星期依然没有解决。今天沉下来好好看了一下logcat,赫然发现我下的数个svc播放程序的问题竟然出奇一致:
05-27 07:53:40.389: D/AndroidRuntime(1173): Shutting down
VM
VM
05-27 07:53:40.389: W/dalvikvm(1173): threadid=1: thread
exiting with uncaught exception (group=0x40a71930)
exiting with uncaught exception (group=0x40a71930)
05-27 07:53:40.459: E/AndroidRuntime(1173): FATAL EXCEPTION:
main
main
05-27 07:53:40.459:
E/AndroidRuntime(1173): java.lang.RuntimeException: Buffer not
large enough for pixels
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)
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)
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)
android.view.View.draw(View.java:13712)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.View.draw(View.java:13596)
android.view.View.draw(View.java:13596)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.ViewGroup.drawChild(ViewGroup.java:2928)
android.view.ViewGroup.drawChild(ViewGroup.java:2928)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.View.draw(View.java:13594)
android.view.View.draw(View.java:13594)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.ViewGroup.drawChild(ViewGroup.java:2928)
android.view.ViewGroup.drawChild(ViewGroup.java:2928)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.View.draw(View.java:13594)
android.view.View.draw(View.java:13594)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.ViewGroup.drawChild(ViewGroup.java:2928)
android.view.ViewGroup.drawChild(ViewGroup.java:2928)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.view.View.draw(View.java:13715)
android.view.View.draw(View.java:13715)
05-27 07:53:40.459: E/AndroidRuntime(1173): at
android.widget.FrameLayout.draw(FrameLayout.java:467)
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)
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
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
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.
InMemoryTileCache.java.patch 488 bytes |
Nov 16, 2012
#3
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 17, 2012
#4
This is the change in the android code:
https://github.com/android/platform_frameworks_base/commit/55adc145d460be4b21de0d77be1f6076c3591e3c#graphics/java/android/graphics/Bitmap.java
这是Android4.2的bug,艹。
现在我正安装低版本的android以测试程序。
对于这个bug的解决方法不是下载低版本的android程序,修改方法如下:
全站熱搜
留言列表