A `MapWidget` built just after another is disposed can lose `mapView#onMapCreated`: the released channel suffix is reused while the old map's async dispose is still in flight
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 30/100
Piste de recherche
Start in mapbox_maps_platform.dart: _SuffixesRegistry.getSuffix() and _MapboxMapsPlatform.dispose(), where the handler is cleared after the awaited platform#releaseMethodChannels. Check how map_widget.dart takes and returns the suffix in initState and dispose. Reproduce with the fake-channel steps in the issue. Done when a map built after another is disposed still receives mapView#onMapCreated, and the suffix is not reused before its release completes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Versions: mapbox_maps_flutter 3.33.0 (mapbox_maps_flutter_mobile 3.33.0), Flutter 3.47.8. Seen on Android 16 (Galaxy S22); the code involved is the Dart layer both platforms share.
What happens
_MapWidgetStatetakes its channel suffix when the State is constructed (mapbox_maps_flutter_mobile/lib/src/map_widget.dart:177) and gives it back synchronously indispose()(:209).- The disposed map's
_MapboxMapsPlatform.dispose()isasync: it awaitsplatform#releaseMethodChannelsand only then calls_channel.setMethodCallHandler(null)onplugins.flutter.io.<suffix>(mapbox_maps_platform.dart:148-157). _SuffixesRegistry.getSuffix()hands outsuffixesAvailable.first(mapbox_maps_platform.dart:232-245), so aMapWidgetwhose State is created a frame later gets that same suffix and registers its own handler on the same channel name (map_widget.dart:222,mapbox_maps_platform.dart:22-27).- When the old map's release reply arrives, its
setMethodCallHandler(null)clears the new map's handler. The new map's nativemapView#onMapCreatedreaches nobody:onMapCreatednever fires, noMapboxMapis handed out, and the map stays on its defaults (ornaments, camera, nothing drawn) until the app restarts.
A second effect of the same reuse: a mapView#onMapCreated sent to a suffix with no listener is queued by the engine's channel buffers and handed to the next listener of that name, so the next map on that suffix can be "created" by a stale message before its own native view exists; its pigeon calls then fail with channel-error, and its real create is ignored (map_widget.dart:301-304).
The events channel (com.mapbox.maps.flutter.map_events.<suffix>) is not affected — it is cleared synchronously at unmount (map_events.dart:71-72) — so the affected map still reports MapLoaded.
Repro (Dart side, on fakes, no device needed)
Two screens, each holding a MapWidget that is built one frame after its screen mounts (a StatefulWidget that shows SizedBox first and the map from a post-frame setState). Swap them under a keyed parent: A → B → A.
- B's map is created (send
mapView#onMapCreatedon its suffix), so it releases on dispose. - Hold B's
platform#releaseMethodChannelsreply. - Swap back to A: A's new map takes B's suffix (0, with one map at a time).
- Complete the held reply, then send
mapView#onMapCreatedon that suffix: A'sonMapCreatedis never called.
The same steps with the reply answered before A's map is built pass.
Suggested fixes (any one)
- Clear the handler in
dispose()only if this platform object still owns the channel, or set it to null synchronously before awaiting the release. - Release the suffix back to the registry only after
platform#releaseMethodChannelscompletes. - Prefer a never-used suffix over a just-released one.
Our workaround, to be removed when this is fixed: the app watches for a map that reports MapLoaded without onMapCreated, or whose first pigeon call fails with channel-error, and rebuilds it under a new key, which takes a fresh suffix.
- Langage dominant
- Dart
- Étoiles
- 382
- Forks
- 205
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de mapbox/mapbox-maps-flutter
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
mapbox/mapbox-maps-flutter#1150 · 1 commentaire ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
mapbox/mapbox-maps-flutter#1144 ·
-
iOS: the map cannot be captured or read by flutter, because it is a platform viewPeut-être pris @Nixxx19 l’a pris il y a 92 jours. Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
mapbox/mapbox-maps-flutter#1142 ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
mapbox/mapbox-maps-flutter#1140 ·
-
Normalize ornament positioning relative to safe areas on iOS and AndroidPeut-être à nouveau libre @maios l’a pris il y a 136 jours, et aucune pull request n’est ouverte. Ouverte
mapbox/mapbox-maps-flutter#1137 · 1 commentaire · 1 réaction · 1 personne assignée ·
Toutes les issues de mapbox/mapbox-maps-flutter
Issues similaires
-
消费码加载时间太长Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
HeZeBang/TechPie-flutter#294 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
ccch1mneyyy/dsh-Go#2192 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
-
[FR] List of Russian bypass appsOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
hiddify/hiddify-app#2724 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
commetchat/commet#1123 ·
Les mainteneurs répondent en général sous 3 jours