close

这几天一直纠结于一个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.





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);
" STYLE="margin: 0px; padding: 0px 8px; border-width: 0px 1px 0px 0px; border-right-style: solid; border-color: rgb(180, 226, 180); width: 24px; font-family: Consolas, 'Liberation Mono', Courier, monospace; line-height: 18px; color: rgba(0, 0, 0, 0.298039); vertical-align: top; text-align: right; -webkit-user-select: none; background-color: rgb(206, 255, 206);">


+
" STYLE="margin: 0px; padding: 0px 8px; border-width: 0px 1px 0px 0px; border-right-style: solid; border-color: rgb(180, 226, 180); width: 24px; font-family: Consolas, 'Liberation Mono', Courier, monospace; line-height: 18px; color: rgba(0, 0, 0, 0.298039); vertical-align: top; text-align: right; -webkit-user-select: none; background-color: rgb(206, 255, 206);">


       // now update the buffer's position
" STYLE="margin: 0px; padding: 0px 8px; border-width: 0px 1px 0px 0px; border-right-style: solid; border-color: rgb(180, 226, 180); width: 24px; font-family: Consolas, 'Liberation Mono', Courier, monospace; line-height: 18px; color: rgba(0, 0, 0, 0.298039); vertical-align: top; text-align: right; -webkit-user-select: none; background-color: rgb(206, 255, 206);">


       int position src.position();
" STYLE="margin: 0px; padding: 0px 8px; border-width: 0px 1px 0px 0px; border-right-style: solid; border-color: rgb(180, 226, 180); width: 24px; font-family: Consolas, 'Liberation Mono', Courier, monospace; line-height: 18px; color: rgba(0, 0, 0, 0.298039); vertical-align: top; text-align: right; -webkit-user-select: none; background-color: rgb(206, 255, 206);">


       position += bitmapBytes >> shift;
" STYLE="margin: 0px; padding: 0px 8px; border-width: 0px 1px 0px 0px; border-right-style: solid; border-color: rgb(180, 226, 180); width: 24px; font-family: Consolas, 'Liberation Mono', Courier, monospace; line-height: 18px; color: rgba(0, 0, 0, 0.298039); vertical-align: top; text-align: right; -webkit-user-select: none; background-color: rgb(206, 255, 206);">


       src.position(position);



     }



 


     /**



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



arrow
arrow
    全站熱搜
    創作者介紹
    創作者 lsx121924 的頭像
    lsx121924

    lsx121924的部落格

    lsx121924 發表在 痞客邦 留言(0) 人氣()