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

Marker.draw NPE at cleanup #659

Closed
devemux86 opened this Issue Aug 25, 2015 · 6 comments

Comments

Projects
None yet
3 participants
@devemux86
Collaborator

devemux86 commented Aug 25, 2015

Playing with many markers on the map, occasionally at Android app exit (i.e. resources cleanup), I have seen NPE inside Marker.draw method, specifically for its bitmap.

Though we check bitmap state at draw start, possible race conditions with Marker.onDestroy manage to nullify it prior draw exit.

It's worth investigating also if Bitmap's enclosing android.graphics.Bitmap is null or recycled at draw start. Probably we need to place checks for that too.

@devemux86 devemux86 added the bug label Aug 25, 2015

@virus-warnning

This comment has been minimized.

Show comment
Hide comment
@virus-warnning

virus-warnning Jan 5, 2016

Contributor

I have this problem too.

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at org.mapsforge.map.android.graphics.AndroidBitmap.getWidth(AndroidBitmap.java:114)
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)

Now I solve this problem by unset Bitmap before mapview.destroyAll()

// Avoid Issue #659, https://github.com/mapsforge/mapsforge/issues/659
mMyLocationMarker.setBitmap(null);
Contributor

virus-warnning commented Jan 5, 2016

I have this problem too.

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at org.mapsforge.map.android.graphics.AndroidBitmap.getWidth(AndroidBitmap.java:114)
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)

Now I solve this problem by unset Bitmap before mapview.destroyAll()

// Avoid Issue #659, https://github.com/mapsforge/mapsforge/issues/659
mMyLocationMarker.setBitmap(null);

devemux86 added a commit that referenced this issue Jan 5, 2016

@devemux86

This comment has been minimized.

Show comment
Hide comment
@devemux86

devemux86 Jan 5, 2016

Collaborator

I added a method to Mapsforge Bitmap for checking its internal (platform) bitmap validity.
Then this check is used centrally in Marker.draw method.

Let's see if we have any issues with that or we need to put the check in other places too.

Collaborator

devemux86 commented Jan 5, 2016

I added a method to Mapsforge Bitmap for checking its internal (platform) bitmap validity.
Then this check is used centrally in Marker.draw method.

Let's see if we have any issues with that or we need to put the check in other places too.

@wish7code

This comment has been minimized.

Show comment
Hide comment
@wish7code

wish7code Feb 5, 2016

Contributor

Looking forward to test this! I'll get a similar exception, although not directly related to markers:

E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object
at org.mapsforge.map.android.graphics.AndroidBitmap.getWidth(AndroidBitmap.java:114)
at org.mapsforge.map.scalebar.MapScaleBar.draw(MapScaleBar.java:264)
at org.mapsforge.map.android.view.MapView.onDraw(MapView.java:291)
at android.view.View.draw(View.java:15231)
at android.view.View.draw(View.java:15140)
...

(Version org.mapsforge:mapsforge:0.6.0)

Contributor

wish7code commented Feb 5, 2016

Looking forward to test this! I'll get a similar exception, although not directly related to markers:

E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object
at org.mapsforge.map.android.graphics.AndroidBitmap.getWidth(AndroidBitmap.java:114)
at org.mapsforge.map.scalebar.MapScaleBar.draw(MapScaleBar.java:264)
at org.mapsforge.map.android.view.MapView.onDraw(MapView.java:291)
at android.view.View.draw(View.java:15231)
at android.view.View.draw(View.java:15140)
...

(Version org.mapsforge:mapsforge:0.6.0)

@devemux86 devemux86 added this to the 0.6.1 milestone Feb 5, 2016

@devemux86

This comment has been minimized.

Show comment
Hide comment
@devemux86

devemux86 Feb 5, 2016

Collaborator

That could happen if the MapScaleBar.destroy was called directly or indirectly from MapView destroy methods and the scale bar (i.e. the map view) is still in use.

Collaborator

devemux86 commented Feb 5, 2016

That could happen if the MapScaleBar.destroy was called directly or indirectly from MapView destroy methods and the scale bar (i.e. the map view) is still in use.

@wish7code

This comment has been minimized.

Show comment
Hide comment
@wish7code

wish7code Feb 5, 2016

Contributor

Thanks emux! Is this intended behaviour or shall I open a new issue?

I was trying to cleanup ressources, when my map frament becomes invisible:
@override
public void setUserVisibleHint(boolean isVisibleToUser) {
if (mMapView != null) {
// save map settings
mMapView.getModel().save(mPreferencesFacade);
mPreferencesFacade.save();
mMapView.getModel().mapViewPosition.destroy();
mMapView.destroyAll();
mMapView = null;
}
}

Contributor

wish7code commented Feb 5, 2016

Thanks emux! Is this intended behaviour or shall I open a new issue?

I was trying to cleanup ressources, when my map frament becomes invisible:
@override
public void setUserVisibleHint(boolean isVisibleToUser) {
if (mMapView != null) {
// save map settings
mMapView.getModel().save(mPreferencesFacade);
mPreferencesFacade.save();
mMapView.getModel().mapViewPosition.destroy();
mMapView.destroyAll();
mMapView = null;
}
}

@devemux86

This comment has been minimized.

Show comment
Hide comment
@devemux86

devemux86 Feb 5, 2016

Collaborator

@wish7code the exception you mentioned should not happen normally, maybe something in your app life cycle?

Calling MapView.destroyAll clears the resources and after that the map host (view / activity / fragment) should not be used again.

So in onDestroy is a good location as seen in our docs.

Collaborator

devemux86 commented Feb 5, 2016

@wish7code the exception you mentioned should not happen normally, maybe something in your app life cycle?

Calling MapView.destroyAll clears the resources and after that the map host (view / activity / fragment) should not be used again.

So in onDestroy is a good location as seen in our docs.

@devemux86 devemux86 closed this Feb 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment