-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ANR adding a polyline #11440
Comments
Thanks for reaching out @RoProducts.
Let us know if any of the above helps. |
Thank you, unfortunately these hints do not resolve the issue, still happening occasionally. Why is ViewPager not completely supported ? |
We are currently using Tagging @tobrun here for more context. |
@RoProducts could you add some code to this issue or provide us with a minimal reproducible example? |
Sure. Actually this is happening also outside the ViewPager after a standard fragment transaction. I'm having an activity in which a (race) setup is done in several steps. The last step is to show the race on the map. For this I'm extending SupportMapFragment. I'm creating the Fragment this way :
In onCreateView of the fragment I'm getting the MapView from SupportMapFragment and add it to the Framelayout of my layout :
The lifecycle of the map is handled by SupportMapFragment then. The actual issue happens "onMapReady" when adding the "race" (a polyline and two markers) to the mapview :
addRace does the following :
As described before occasionally this freezes at To clarify : I'm using this fragment twice, in the race setup and in a ViewPager environment which is the main screen of this app providing different fragments. The issue is happening in both environments, always after inflating the layout and adding the race onMapReady. I'm only recently extending SupportMapFragment, this was also happening when defining the mapview in XML in my own layout and handling the mapview lifecyle myself. Initially it seemed to resolve to use SupportMapFragment as I could inflate the fragment for about 10-15 cycles without issues. But some days later it freezed again. Thank you |
@RoProducts It's not advised to extend SupportMapFragment in the way you are doing. MapView is already inflated and added to the layout container, you are readding it which is not allowed. If you want other content in your Fragment besides the basic map you will need to roll your own fragment that extends from Fragment. Feel free to reach out if you hit any other issue but root cause has been identified. Closing. |
I do not agree. Maybe you missed the last paragraph :
I'm doing this rather unusual way of extending SupportMapFragment only to overcome this issue. |
could you point out which line is causing a freeze? |
|
Fyi : I did not find a way to overcome this issue. I'm using now a LineString in a LineLayer to add my polyline to the map. This is currently working without issues. |
I am also struggling with this issue. I can replicate ANR quite easily with OnePlus3 (API 26) by adding hundreds of Polylines. No ViewPagers or tricks with GLSurfaceView in use. Curiously, Samsung S8 (API 26) works better but eventually ANR is caught also there. Here are couple of ANR stack traces from ANRWatchDog: ================================================================ ================================================================ I'm not 100% sure about this, but I recall version 5.3 was working ok. |
@tobrun @LukasPaczos any updates on this? edit: The issue seems to be with the new |
I keep getting ANRs with mapbox and similar stacktraces. mapbox_renderTextureMode didn't help. |
Any updates on this issue. We are getting a lot of ANRs |
@rohitr308 I fixed all of the ANRs we were seeing (related to mapbox) by switching off annotations. I now use SymbolLayers with Geojson sources and have seen an improvement in performance and almost no ANRs. |
@cvance Thank you. How do I turn off the annotation? Looks like GeoJson works fine for static locations. How about locations that change constantly? |
You're adding a polyline annotation to the map right? If so try something like this instead.
then if you need to change the location. You can do so by keeping a reference to the source but I'd suggest getting it from the map. Then just update the geojson and the layer will automatically update.
Someone from Mapbox can correct me if I'm wrong or there is better documentation but I've had success doing it this way. |
@cvance thanks a lot for the above suggestion. A strange thing happens when we add polylines via the above. They appear, then disappear... Not entirely sure why. If we switch to map.addPolyline - then they stay all the time. Might you know what we're running into? |
And an update for Mapbox: We're getting this same stack trace on SDK 5.5.3. Thinking the cause is likely OOM or such. Will help to know what it might be. We're adding a polygon and a polyline to the map, about 20 of them at a time.
Stacktrace looks like below:
|
An update on the issue above. We removed the calls to "addPolyline". And now have ANR in MapboxMap.clear(), and MapboxMap.addPolygon which are all in the same "redrawMap" sequence. Repro Steps:
Actual Results: Map 1: mapBoxMap.clear(); Triggers (occurs 3x total around time of onMapReady) :
on 2 triggers:
We get a mixture of ANRs in "addPolyline", "addPolygon", and "clear()" . Above was one of the "addPolyline" ANRs. Below are the "addPolygon" and "clear()" stack traces. mapboxMap.addPolygon
mapboxMap.clear()
|
@jsun-dd thanks for the detailed write up, been trying my best to reproduce with provided code, public class SimpleMapActivity extends AppCompatActivity {
private MapView mapView;
private final Handler handler = new Handler();
private final Random random = new Random();
private final Runnable runnable = new Runnable() {
@Override
public void run() {
mapboxMap.clear();
addRandomStuff();
handler.postDelayed(this, 250);
}
};
private MapboxMap mapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_simple);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> {
this.mapboxMap = mapboxMap;
loopRandomStuff();
});
}
private void loopRandomStuff() {
handler.post(runnable);
}
private void addRandomStuff() {
for (int i = 0; i < random.nextInt() + 20; i++) {
List<LatLng> latLngs = new ArrayList<>();
for (int j = 0; j < random.nextInt() + 10; j++) {
latLngs.add(createRandomLatLng());
}
addHeatmapRegion(latLngs, Color.argb(255, random.nextInt(255), random.nextInt(255), random.nextInt(255)));
}
}
private void addHeatmapRegion(List<LatLng> decodedPolyline, @ColorInt int fillColor) {
// Draw the polygon with fill color
PolygonOptions polygonOptions = new PolygonOptions();
polygonOptions.addAll(decodedPolyline);
polygonOptions.fillColor(fillColor);
mapboxMap.addPolygon(polygonOptions);
// Work around for Mapbox polygon stroke width bug:
// https://github.com/mapbox/mapbox-gl-native/issues/324, and
// https://github.com/mapbox/react-native-mapbox-gl/issues/435
// Draw the border polyline with the same points on top of the polygon.
PolylineOptions polylineOptions = new PolylineOptions()
.addAll(decodedPolyline)
.color(Color.WHITE)
.width(2f);
mapboxMap.addPolyline(polylineOptions);
}
private LatLng createRandomLatLng() {
return new LatLng((random.nextDouble() * -180.0) + 90.0,
(random.nextDouble() * -360.0) + 180.0);
}
... // other lifecycle methods As seen in gif below this is not resulting in any ANR: I'm not able to fully replicate your setup, would you be able to do the following tests? or provide a minimal reproducible example?
re. #11440 (comment), we are tracking this issue in #11877. |
@tobrun thanks a lot for the update. I can get you a setup that more closely reproduces our code. I'll try first your tips, and also upgrading to Mapbox 6+, as that might be a much better use of time for simply getting us to a better state. Will update again soon. |
Annotations are deprecated and are being replaced by the annotations plugin. |
**Platform:Android
**Mapbox SDK version:5.5.0
Steps to trigger behavior
Expected behavior
Overlay is displayed and map is responsive
Actual behavior
map freezes
I'm using ANRWatchDog to get the stack trace.
This issue has been reported in #9709 and is marked as resolved. But it seems to appear still.
This was happening even more often when I was not using SupportMapFragment but added a mapView (and its lifecycle) to a android.support.v4.app.Fragment programmatically. Using SupportMapFragment seemed to have solved it, but now I faced it again.
Caused by: com.github.anrwatchdog.ANRError$$$_Thread: Apollo Dispatcher (state = TIMED_WAITING)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at java.lang.reflect.Method.invoke(Native Method)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at android.os.Looper.loop(Looper.java:136)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.MessageQueue.nativePollOnce(Native Method)
at com.mapbox.mapboxsdk.maps.NativeMapView.onMapChanged(NativeMapView.java:862)
at com.mapbox.mapboxsdk.maps.MapView.onMapChange(MapView.java:575)
at com.mapbox.mapboxsdk.maps.MapView$MapCallback.onMapChanged(MapView.java:1060)
at com.mapbox.mapboxsdk.maps.MapView$MapCallback.onMapReady(MapView.java:1075)
at ch.jespr.jespr.ui.fragment.MapboxRaceFragment.onMapReady(MapboxRaceFragment.java:129)
at ch.jespr.jespr.ui.overlay.OverlayManager.addRace(OverlayManager.java:377)
at com.mapbox.mapboxsdk.maps.MapboxMap.addPolyline(MapboxMap.java:1312)
at com.mapbox.mapboxsdk.maps.AnnotationManager.addPolyline(AnnotationManager.java:244)
at com.mapbox.mapboxsdk.maps.PolylineContainer.addBy(PolylineContainer.java:31)
at com.mapbox.mapboxsdk.maps.NativeMapView.addPolyline(NativeMapView.java:404)
at com.mapbox.mapboxsdk.maps.NativeMapView.nativeAddPolylines(Native Method)
at com.mapbox.mapboxsdk.maps.NativeMapView.onMapChanged(NativeMapView.java:862)
at com.mapbox.mapboxsdk.maps.MapView.onMapChange(MapView.java:575)
at com.mapbox.mapboxsdk.maps.MapView$MapCallback.onMapChanged(MapView.java:1065)
at com.mapbox.mapboxsdk.maps.MapboxMap.onUpdateRegionChange(MapboxMap.java:191)
at com.mapbox.mapboxsdk.maps.AnnotationManager.update(AnnotationManager.java:90)
at com.mapbox.mapboxsdk.annotations.MarkerViewManager.update(MarkerViewManager.java:471)
at com.mapbox.mapboxsdk.annotations.MarkerViewManager.invalidateViewMarkersInVisibleRegion(MarkerViewManager.java:485)
at com.mapbox.mapboxsdk.maps.MapboxMap.getMarkerViewsInRect(MapboxMap.java:1274)
at com.mapbox.mapboxsdk.maps.AnnotationManager.getMarkerViewsInRect(AnnotationManager.java:208)
at com.mapbox.mapboxsdk.maps.MarkerContainer.obtainViewsIn(MarkerContainer.java:171)
at com.mapbox.mapboxsdk.maps.NativeMapView.queryPointAnnotations(NativeMapView.java:471)
at com.mapbox.mapboxsdk.maps.NativeMapView.nativeQueryPointAnnotations(Native Method)
Caused by: com.github.anrwatchdog.ANRError$$$_Thread: main (state = RUNNABLE)
com.github.anrwatchdog.ANRError: Application Not Responding
The text was updated successfully, but these errors were encountered: