anhtuanmai / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

NPE in Canvas after MapView.onAnimationEnd() on Huawei devices #374

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Unknown. I've received a number of bug reports (ACRA). They all come from 
Huawei devices (u8150, u8800) on Android 2.2/2.2.1.

What version of the product are you using? On what operating system?
3.0.8 on Android 2.2/2.2.1

Please provide any additional information below.

java.lang.NullPointerException
 at android.graphics.Canvas.<init>(Canvas.java:82)
 at org.osmdroid.tileprovider.MapTileProviderBase$ZoomInTileLooper.handleTile(SourceFile:278)
 at org.osmdroid.tileprovider.MapTileProviderBase$ScaleTileLooper.handleTile(SourceFile:238)
handleTile
 at org.osmdroid.util.TileLooper.loop(SourceFile:36)
                                 initialiseLoop
                                 handleTile
                                 finaliseLoop
 at org.osmdroid.tileprovider.MapTileProviderBase.getMapTile(SourceFile:194)
                                                  detach
                                                  rescaleCache
 at org.osmdroid.views.MapView.setZoomLevel(SourceFile:345)
 at org.osmdroid.views.MapView.onAnimationEnd(SourceFile:911)
 at android.view.ViewGroup.finishAnimatingView(ViewGroup.java:3275)
 at android.view.ViewGroup.drawChild(ViewGroup.java:1661)
 at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
 at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
 at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
 at android.view.View.draw(View.java:6743)
 at android.widget.FrameLayout.draw(FrameLayout.java:352)
 at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
 at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
 at android.view.View.draw(View.java:6743)
 at android.widget.FrameLayout.draw(FrameLayout.java:352)
 at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
 at android.view.ViewRoot.draw(ViewRoot.java:1407)
 at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
 at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
 at android.os.Handler.dispatchMessage(Handler.java:99)
 at android.os.Looper.loop(Looper.java:123)
 at android.app.ActivityThread.main(ActivityThread.java:4627)
 at java.lang.reflect.Method.invokeNative(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:521)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
 at dalvik.system.NativeStart.main(Native Method)

Original issue reported on code.google.com by osei...@gmail.com on 9 Oct 2012 at 3:40

GoogleCodeExporter commented 8 years ago
I had a look at the source code for Canvas and it appears that the passed 
bitmap is null:

81  public  [More ...] <a name="Canvas.<init>(android.graphics.Bitmap)" 
style="padding: 0px; margin: 0px; ">Canvas(Bitmap bitmap) {
82    if (!bitmap.isMutable()) {
83      throw new IllegalStateException(
84        "Immutable bitmap passed to Canvas constructor");
85    }

A look at the calling code suggests that the createBitmap method call in 
ZoomInTileLooper returns null as Bitmap:
                final Bitmap bitmap = Bitmap.createBitmap(pTileSizePx, pTileSizePx, Bitmap.Config.ARGB_8888);
                final Canvas canvas = new Canvas(bitmap);

Checking the source for Bitmap this refers to a native method, which might 
explain why the fault only happens on specific devices:

  public static Bitmap createBitmap(int width, int height, Config config) {
    Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
    bm.eraseColor(0);    // start with black/transparent pixels
    return bm;
  }

But if the Bitmap returned by createBitmap was null it would fail with a NPE in 
bm.eraseColor(0). Is it possible that Huawei uses different libraries?

Original comment by osei...@gmail.com on 9 Oct 2012 at 3:42

GoogleCodeExporter commented 8 years ago
In the latest source the code has been changed to use Bitmap.Config.RGB_565 
instead of Bitmap.Config.ARGB_8888.  It's possible that may help.

Original comment by neilboyd on 9 Oct 2012 at 5:42

GoogleCodeExporter commented 8 years ago
I have noticed that change and will post here if it happens again with the 
changed code.

Original comment by osei...@gmail.com on 9 Oct 2012 at 6:57

GoogleCodeExporter commented 8 years ago
This still occurs with Bitmap.Config.RGB_565 - I just got more error reports. 
Any ideas?

Original comment by osei...@gmail.com on 25 Mar 2013 at 2:53