mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

When I place too many markers on the map at once, it will lead to native error

Open JennyHao123 opened this issue 8 years ago • 4 comments

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!");
        }
  1. when status changes, remove all current markers
map.removeAnnotations();
  1. 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

JennyHao123 avatar Aug 06 '18 18:08 JennyHao123

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?

LukasPaczos avatar Aug 07 '18 16:08 LukasPaczos

I'm facing the same issue with SDK version 6.2.1 and the count of custom markers is more than 600

rahulabrol avatar Aug 10 '18 12:08 rahulabrol

@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!");
}

tobrun avatar Aug 13 '18 07:08 tobrun

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 .

JennyHao123 avatar Aug 13 '18 14:08 JennyHao123