rksahu1987 / osmdroid

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

RuntimeException: Canvas: trying to use a recycled bitmap in MapTileProviderBase #385

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi Guys,

i got an Escalation Log Report from my Apps in the wild.
The App crashes cause of an error in osmdroid.

Stack Trace

RuntimeException: Canvas: trying to use a recycled bitmap 
android.graphics.Bitmap@407a6048
android.graphics.Canvas.throwIfRecycled(Canvas.java:955)
android.graphics.Canvas.drawBitmap(Canvas.java:1044)
org.osmdroid.tileprovider.MapTileProviderBase$ZoomInTileLooper.a(SourceFile:309)
org.osmdroid.tileprovider.MapTileProviderBase$ScaleTileLooper.a(SourceFile:266)
org.osmdroid.util.TileLooper.a(SourceFile:36)
org.osmdroid.tileprovider.MapTileProviderBase.a(SourceFile:222)
org.osmdroid.views.MapView.a(SourceFile:338)
org.osmdroid.views.MapController.a(SourceFile:78)
org.osmdroid.views.MapController.a(SourceFile:54)
de.komoot.android.a.af.a(SourceFile:118)
de.komoot.android.activity.lp.run(SourceFile:1017)
android.os.Handler.handleCallback(Handler.java:587)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:130)
android.app.ActivityThread.main(ActivityThread.java:3687)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:507)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
dalvik.system.NativeStart.main(Native Method)

I am using osmdroid r1126

The defect is in the ClassMapTileProvider.ZoomInTileLooper
in Method handleTile(...) at Line 309.

oldBitmap was already been reycled but was still in mTileCache.
It seems there is an race conditon.

I dont know the side effects if i will fix the problem by myself.
So i want to discuss if we can the oldBitmap with isRecycled() to prevent a 
draw of oldBitmap.

Some months befor i tryed these fix, but i results to the problem, 
that some black tiles can apprearon the map when zooming in.
Be careful before a simple solution.
But maybe that was an othe problem, i dont know cause i updates to a new 
version of osmdroid.

Give me Feedback
Greetings from Berlin
Arne

Original issue reported on code.google.com by arne.koe...@gmail.com on 23 Nov 2012 at 2:57

GoogleCodeExporter commented 8 years ago
I got same issue. It is intermittent but I saw the debug message below

//====================================
12-07 18:43:28.457: E/AndroidRuntime(19803): FATAL EXCEPTION: main
12-07 18:43:28.457: E/AndroidRuntime(19803): java.lang.RuntimeException: 
Canvas: trying to use a recycled bitmap android.graphics.Bitmap@4070aab0
12-07 18:43:28.457: E/AndroidRuntime(19803):    at 
android.graphics.Canvas.throwIfRecycled(Canvas.java:955)
12-07 18:43:28.457: E/AndroidRuntime(19803):    at 
android.graphics.Canvas.drawBitmap(Canvas.java:1044)
12-07 18:43:28.457: E/AndroidRuntime(19803):    at 
org.osmdroid.tileprovider.MapTileProviderBase$ZoomInTileLooper.handleTile(MapTil
eProviderBase.java:309)
12-07 18:43:28.457: E/AndroidRuntime(19803):    at 
org.osmdroid.tileprovider.MapTileProviderBase$ScaleTileLooper.handleTile(MapTile
ProviderBase.java:266)
12-07 18:43:28.457: E/AndroidRuntime(19803):    at 
org.osmdroid.util.TileLooper.loop(TileLooper.java:36)
12-07 18:43:28.457: E/AndroidRuntime(19803):    at 
org.osmdroid.tileprovider.MapTileProviderBase.rescaleCache(MapTileProviderBase.j
ava:222)
12-07 18:43:28.457: E/AndroidRuntime(19803):    at 
org.osmdroid.views.MapView.setZoomLevel(MapView.java:342)
12-07 18:43:28.457: E/AndroidRuntime(19803):    at 
org.osmdroid.views.MapController.setZoom(MapController.java:228)
//================================================

Original comment by jaehyung...@bientus.com on 7 Dec 2012 at 9:46

GoogleCodeExporter commented 8 years ago
Issue 384 has been merged into this issue.

Original comment by kurtzm...@gmail.com on 3 Jan 2013 at 8:00

GoogleCodeExporter commented 8 years ago
This issue is a little more complicated than you'd realize on first glance. It 
actually permeates the entire project. Whenever osmdroid gets a tile from the 
cache, that tile could be recycled at any time and be rendered useless. 
Normally this won't happen - when you request a tile it puts it at the front of 
the tile cache "queue" so it will be the last to be removed and recycled. But 
under certain circumstances - like this one - that maybe push tiles out of the 
queue quickly it could happen.

As of Gingerbread, recycle() shouldn't really need to be called, so we could up 
the API requirements and drop the recycle() calls but I don't think we're going 
that route just yet.

We could require synchronize() whenever we get a tile from the cache. We would 
have to put that everywhere.

The final solution is to just try/catch the tile scalers since that is where 
the issue definitively pops up under normal circumstances. That doesn't solve 
the larger problem, but since it doesn't seem to pop up in the TileOverlay for 
instance then maybe it's all we need.

Original comment by kurtzm...@gmail.com on 24 Jan 2013 at 10:42

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
In r1149: Updates issue 385. Only call recycle() if < GINGERBREAD. In later 
builds there is no need for explicitly calling recycle() and it can cause 
exceptions as seen
in issue 385.

Original comment by kurtzm...@gmail.com on 26 Feb 2013 at 9:16