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

Setting marker position in loop results in crash (Fatal signal 11 (SIGSEGV))

Open shantanu-vyas opened this issue 9 years ago • 5 comments

While updating a markers position in a threaded loop at a rate of once ever 500ms mapbox will crash with a sigsegv after some variant amount of time. The code would look something like this

public void tempUpdateMarkers() { Marker marker = mMapboxMap.addMarker(new MarkerOptions().position(new LatLng(0,0).title("marker")); Runnable markerRun = new Runnable() { @Override public void run() { marker.setPosition(new LatLng(marker.getPosition().getLatitude()+.001,marker.getPosition().getLongitude()+.001)); } }; ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1); exec.scheduleAtFixedRate(markerRun, 0, 500, TimeUnit.MILLISECONDS); }

Should this be handled with a animator instead?

Platform: Samsung Galaxy S Tab2, have also tested on Amazon fire 10inch Mapbox SDK version:4.2.2 stable

Steps to trigger behavior

  1. Update a markers location in some kind of loop at a fixed interval of time
  2. Run app
  3. Wait for crash, occurs at varying amount of times from a couple seconds to a couple minutes

Expected behavior

Marker will update position indefinitely.

Actual behavior

App crashes A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 687 (pool-3-thread-1)

shantanu-vyas avatar Feb 19 '17 20:02 shantanu-vyas

@shantanu-vyas thanks you for reaching out, can you post the full stacktrace (the lines below the fatal signal 11)?

tobrun avatar Feb 20 '17 06:02 tobrun

That's actually all I get. I dont get a full stack trace other than that.

shantanu-vyas avatar Feb 20 '17 15:02 shantanu-vyas

ScheduledThreadPoolExecutor is going to run the Runnable on some thread other than the main thread, right? That's not supported: MapboxMap methods must be called from the main thread.

jfirebaugh avatar Feb 20 '17 16:02 jfirebaugh

@shantanu-vyas, @jfirebaugh remark is on point. Porting your code to a main thread equivalent would be:

        final Handler handler = new Handler();
        final Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)));
        Runnable markerRun = new Runnable() {
          @Override
          public void run() {
            marker.setPosition(new LatLng(marker.getPosition().getLatitude() + .001,
              marker.getPosition().getLongitude() + .001));
            handler.postDelayed(this, 500);
          }
        };
        handler.post(markerRun);

Wasn't able to reproduce your crash with this code. Thank you for reaching out, closing this issue as resolved.

tobrun avatar Feb 20 '17 17:02 tobrun

AH, thank you so much.

shantanu-vyas avatar Feb 20 '17 22:02 shantanu-vyas