-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Using onDidBecomeIdle
listener with snapshotter creates infinite loop
#14263
Comments
@chloekraw I believe that is expected behavior. OnDidBecomeIdleListener listener = new IdleSnapshotter(mapboxMap) {
public void onDidBecomeIdle() {
mapboxMap.removeOnDidBecomeIdleListener(this);
mapboxMap.snapshot(snapshot -> {
...
mapboxMap.addOnDidBecomeIdleListener(this);
});
}
};
mapView.addOnDidBecomeIdleListener(listener); @tobrun what do you think? |
@alexshalamov is right, this is to be expected: Suggested workaround works: Full code for that in #14270 |
Thanks @tobrun @alexshalamov and thank you for making it an example! |
@tobrun btw, it is not a workaround (I think 😄), generic pattern when there is a need break recursion. For example, do something that generates event from within an event handler. |
We need to relook into this. It seems we still have recursion with #14263 (comment) though it doesn't crash/freeze as before. When adding logging to add/remove of the listener and having the map idle I'm seeing:
|
@tobrun I briefly debugged test app, it looks like android (texture / surface view) |
That this occurs is actually also expected, we go through the following events:
I could think of some hacky workarounds but we might be able to fix this up more cleanly. For context, we have 2 API's for generating an image from a map. The one used here, To cleanly resolve this issue, we could add support of creating an image in |
It was suggested to add a delay before adding the idle listener back. I'm worried about this solution, because it could be possible that the map stops being idle during or shortly after the snapshot, and then becomes idle again before the listener is added back. |
Been looking into this and atm we can't distinguish if an emitted idle event is associated with a snapshot or by another invalidation (eg. map interaction). I'm punting on that the idle event API is incompatible with MapboxMap#snapshot for now (adding some javadoc to reflect it). Long term, we should revisit the snapshot api with bindgen and move the logic to core instead of handling it in the android binding. By using |
Steps to trigger behavior
Get the map to take a snapshot whenever the map is idle, using the
onDidBecomeIdle
event added in #13513 to close #13469 / mapbox/mapbox-gl-js#7625:Reproduce with code like this in
onCreate
(h/t @samfader):Expected behavior
Taking a snapshot should not be an action that causes the
onDidBecomeIdle
listener to restart.Actual behavior
The map never stops firing the idle event --> taking a snapshot --> firing an idle event --> taking a snapshot.
cc: @tmpsantos
The text was updated successfully, but these errors were encountered: