Setting marker position in loop results in crash (Fatal signal 11 (SIGSEGV))
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
- Update a markers location in some kind of loop at a fixed interval of time
- Run app
- 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 thanks you for reaching out, can you post the full stacktrace (the lines below the fatal signal 11)?
That's actually all I get. I dont get a full stack trace other than that.
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.
@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.
AH, thank you so much.