Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LayerManager exception while destruction #545

Closed
alvaro-arranz opened this issue Nov 17, 2014 · 7 comments
Closed

LayerManager exception while destruction #545

alvaro-arranz opened this issue Nov 17, 2014 · 7 comments

Comments

@alvaro-arranz
Copy link

Hi,

I am randomly getting this exception when destroying my Android Activity:

FATAL EXCEPTION: LayerManager
Process: com.example, PID: 32261
java.lang.NullPointerException
at org.mapsforge.map.android.graphics.AndroidBitmap.getWidth(AndroidBitmap.java:113)
at org.mapsforge.map.layer.overlay.Marker.draw(Marker.java:72)
at org.mapsforge.map.layer.LayerManager.doWork(LayerManager.java:90)
at org.mapsforge.map.util.PausableThread.run(PausableThread.java:140)

I guess it is triggered by any of the destroy() functions usually called: Layer.destroy(), MapView.destroy() or TileCache.destroy(). I am using a cloned code from dev. Any guess??

By the way, I hope I am writing the issue in the correct place :)

Thank you

@devemux86
Copy link
Collaborator

Yes you are in the correct place!

Have you initialized properly the AndroidGraphicFactory as mentioned here?

And also have you followed the proper library life cycle as mentioned there or the Samples app?

@alvaro-arranz
Copy link
Author

Hi devemux86,

Yes, I think everything is initialized as it is suggested and similarly to the Samples. It actually works fine 95% of times. I am not using the android:configChanges option in the manifest and it occurs always during the destruction-creation cycle of the activity. I have noticed also that an InterruptedException occurs first:

W/System.err﹕ java.lang.InterruptedException
W/System.err﹕ at java.lang.VMThread.sleep(Native Method)
W/System.err﹕ at java.lang.Thread.sleep(Thread.java:1013)
W/System.err﹕ at java.lang.Thread.sleep(Thread.java:995)
W/System.err﹕ at com.bugsense.trace.DefaultExceptionHandler.uncaughtException(Unknown Source)
W/System.err﹕ at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
W/System.err﹕ at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

I am using Bugsense (now called Splunk MINT) for exception-catching. I am using a map with quite a lot of different layers. I have also noticed that if I run the application with the basic map with no overlays, everything works fine and no exceptions are thrown. Maybe it is a race condition of trying to redraw a layer that was destroyed or something similar?

Thank you

@devemux86
Copy link
Collaborator

Any particular reason for having the activity to restart at device orientation changes?

Check also the ChangingBitmaps example at Samples with more info about handling the overlay marker bitmaps during the life cycle.

@ludwigb
Copy link
Collaborator

ludwigb commented Nov 18, 2014

I think this is most likely due to a missing incrementRefCount() on the bitmap, particularly if you are using the same bitmap for more than one marker. As Emux pointed out, the ChangingBitmaps example is perhaps closest to your case.

@alvaro-arranz
Copy link
Author

Yes, I haven't found the bug yet but it is probably the case. Emux, I will work on the example you have mentioned and if I find a solution (probably a bug in my code) I will let you know.

Thank you both!

@ludwigb
Copy link
Collaborator

ludwigb commented Nov 28, 2014

I think this problem has been resolved through the coding advice given, so I am closing this issue.

@ludwigb ludwigb closed this as completed Nov 28, 2014
@alvaro-arranz
Copy link
Author

Hi,

I tracked the problem to the Marker.onDestroy() method. The problem was that this method decrements the ref count of the Bitmap, so when the application gets destroyed it gets ready to be released. However, when the application gets created again, the bitmap tries to be reused. I think that's why the exception is randomly thrown, because it gets destroyed when the garbage collector gets into action (I am just guessing).
I solved it by incrementing the ref count of the bitmap when it is created. I think that is probably the same as not destroying the Marker object. No exception occurs, but not sure if I will have memory issues later.

Thank you guys for your advice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants