sudden NPE

31 views
Skip to first unread message

M. Dietrich

unread,
Jul 1, 2015, 1:33:05 PM7/1/15
to mapsfo...@googlegroups.com
i had this NPE today:

07-01 19:28:18.232 E/org.pyneo.sample( 3008): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.android.graphics.AndroidBitmap.getWidth(AndroidBitmap.java:113)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.core.mapelements.SymbolContainer.<init>(SymbolContainer.java:42)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.core.mapelements.SymbolContainer.<init>(SymbolContainer.java:33)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.layer.renderer.DatabaseRenderer.renderPointOfInterestSymbol(DatabaseRenderer.java:373)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.rendertheme.renderinstruction.Symbol.renderNode(Symbol.java:83)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.rendertheme.rule.Rule.matchNode(Rule.java:79)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.rendertheme.rule.RenderTheme.matchNode(RenderTheme.java:154)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.layer.renderer.DatabaseRenderer.renderPointOfInterest(DatabaseRenderer.java:427)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.layer.renderer.DatabaseRenderer.processReadMapData(DatabaseRenderer.java:413)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.layer.renderer.DatabaseRenderer.executeJob(DatabaseRenderer.java:184)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.layer.renderer.MapWorker.renderTile(MapWorker.java:88)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.layer.renderer.MapWorker.doWork(MapWorker.java:65)
07-01 19:28:18.232 E/org.pyneo.sample( 3008): at org.mapsforge.map.util.PausableThread.run(PausableThread.java:140)

quite unsure how that happened, it's just the simple sample with some additions and it happend after screen rotation. maybe the line numbers give you a hint what happened?

M. Dietrich

unread,
Jul 1, 2015, 1:36:40 PM7/1/15
to mapsfo...@googlegroups.com
not to mention: i can't reproduce it :/

ah: i use a custom theme (this Tiramisu_3_0_beta1 ...), maybe that's to blame?

Emux

unread,
Jul 1, 2015, 1:44:32 PM7/1/15
to mapsfo...@googlegroups.com
It tries to access a recycled bitmap.
After device screen orientation change by default Android restarts the activity.
So here we have Mapsforge cleanup and immediate restart (probably racing conditions).

Usually you can disable that behavior in manifest (see Samples) with:
android:configChanges="keyboardHidden|orientation|screenSize"

BTW you have to make sure that the life cycle of Mapsforge resources in the app is handled right (as seen in Getting-Started snippet).

Testing of that situation can be done with consecutive device orientation changes between portrait and landscape.

--
Emux
Cruiser - Atlas

M. Dietrich

unread,
Jul 1, 2015, 4:33:21 PM7/1/15
to mapsfo...@googlegroups.com


Am Mittwoch, 1. Juli 2015 19:44:32 UTC+2 schrieb Emux:
Usually you can disable that behavior in manifest (see Samples) with:
android:configChanges="keyboardHidden|orientation|screenSize"
 
which i do not do in the samples intentionally to test exactly that ;)
 
BTW you have to make sure that the life cycle of Mapsforge resources in the app is handled right (as seen in Getting-Started snippet).
 
it's more or less a copy of exactly that sample. you may take a look here: https://github.com/emdete/ItsDown/blob/master/mapsforge/08.pimped/src/main/java/org/pyneo/android/gui/Map.java
 
Testing of that situation can be done with consecutive device orientation changes between portrait and landscape.

for sure i did exactly that  but it did not happen again :/

but if you're sure it's my fault it's fine and i will take care. thanks!

Ludwig

unread,
Jul 1, 2015, 4:50:05 PM7/1/15
to mapsfo...@googlegroups.com
As Emux said, it is caused by accessing a recycled bitmap. The most probable cause is that the same bitmap is used more than once but the ref count is not increased accordingly. 



--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/9ddbd1f9-139e-4f7c-8cf7-6bf3761df457%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Emux

unread,
Jul 2, 2015, 2:12:19 AM7/2/15
to mapsfo...@googlegroups.com
On 01/07/2015 11:33 μμ, M. Dietrich wrote:
but if you're sure it's my fault it's fine and i will take care. thanks!

No I'm not saying that, we may have rare isolation issue with a recycled bitmap.

I checked our issues list and we had in the past cases with fast orientation changes that were fixed.

Can you open a new issue describing the situation, to monitor this too?

BTW I recommend to try removing the onStart / onStop methods and put their code in onCreate / onDestroy respectively.

M. Dietrich

unread,
Jul 2, 2015, 7:49:56 AM7/2/15
to mapsfo...@googlegroups.com


Am Donnerstag, 2. Juli 2015 08:12:19 UTC+2 schrieb Emux:
BTW I recommend to try removing the onStart / onStop methods and put their code in onCreate / onDestroy respectively.

yes, i got that hint from a android dev recently as well, he said it's not guaranteed that these will be called. i will try that.
Reply all
Reply to author
Forward
0 new messages