When I place too many markers on the map at once, it will lead to native error
Steps to reproduce
1.Place hundreds of markers with lat&lng on the map like this
for (int i=0;i<100;i++) {
IconFactory iconFactory = IconFactory.getInstance(myContext);
Icon icon = iconFactory.fromResource(R.drawable.mapbox_mylocation_icon_default);
double gps_coords[] = tool.gps_fromxy(originCoords[0], originCoords[1], particles[i].state.x, particles[i].state.y);
MarkerOptions userLocationMarker = new MarkerOptions()
.position(new LatLng(gps_coords[0], gps_coords[1]))
.icon(icon);
map.addMarker(userLocationMarker);
Log.e("PDR", "drawParticles: Placed marker!");
}
- when status changes, remove all current markers
map.removeAnnotations();
- Then redraw hundreds of markers with lat&lng
Expected behavior
can draw and redraw those markers properly
Actual behavior
when the number of markers is tens, it is fine. But when I add the markers to 100 or more, it will lead to a native error like this. I can provide tombstone log if you need them.
08-06 14:13:42.128 19673-19673/com.mcmaster.wiser.idyll A/libc: /usr/local/google/buildbot/src/android/ndk-r13-release/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:74: void abort_message(const char *, ...): assertion "terminating with uncaught exception of type std::bad_alloc: std::bad_alloc" failed
Fatal signal 6 (SIGABRT), code -6 in tid 19673 (ter.wiser.idyll)
Configuration
Android versions: API 25 Device models: SGH-I337M Mapbox SDK versions: 5.1.2
Thanks for reaching out @JennyHao123!
I'm unable to reproduce the issue even with 10000 features in place. I'm not seeing any excessive memory growth either. Could you retest using the latest Maps SDK version and while using a different bitmap/drawable?
I'm facing the same issue with SDK version 6.2.1 and the count of custom markers is more than 600
@JennyHao123 could you please optimize your for loop? You are creating bitmaps with each loop invocation which is not needed:
IconFactory iconFactory = IconFactory.getInstance(myContext);
Icon icon = iconFactory.fromResource(R.drawable.mapbox_mylocation_icon_default);
double[] gps_coords;
MarkerOptions userLocationMarker;
for (int i=0;i<100;i++) {
gps_coords] = tool.gps_fromxy(originCoords[0], originCoords[1], particles[i].state.x, particles[i].state.y);
userLocationMarker = new MarkerOptions()
.position(new LatLng(gps_coords[0], gps_coords[1]))
.icon(icon);
map.addMarker(userLocationMarker);
Log.e("PDR", "drawParticles: Placed marker!");
}
The function of my app is to monitor the particles' change for a particle filter. So after a sensor event, all the particles shall move to a new place. So I have to clear all markers before the loop starts, and reset them to new positions in the loop. I didn't find another way to do this. Do you have some suggestion?
On Mon, Aug 13, 2018 at 3:49 AM, Tobrun [email protected] wrote:
@JennyHao123 https://github.com/JennyHao123 could you please optimize your for loop? You are creating bitmaps with each loop invocation which is not needed:
IconFactory iconFactory = IconFactory.getInstance(myContext);Icon icon = iconFactory.fromResource(R.drawable.mapbox_mylocation_icon_default);double[] gps_coords;MarkerOptions userLocationMarker;for (int i=0;i<100;i++) { gps_coords] = tool.gps_fromxy(originCoords[0], originCoords[1], particles[i].state.x, particles[i].state.y); userLocationMarker = new MarkerOptions() .position(new LatLng(gps_coords[0], gps_coords[1])) .icon(icon); map.addMarker(userLocationMarker); Log.e("PDR", "drawParticles: Placed marker!"); }
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-gl-native/issues/12555#issuecomment-412435836, or mute the thread https://github.com/notifications/unsubscribe-auth/AoMx9uBbkeokF84911goNkRxBUEsh2zVks5uQS-PgaJpZM4Vw3f4 .