mapbox / mapbox/mapbox-maps-flutter

Exception thrown after calling `dispose()` on MapboxMap

Open
#409 11 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
380
Forks
204
PR merge metrics
No merged PRs in 30d

Description

## Environment
- Flutter version: `3.16.9`
- mapbox_maps_flutter version: `0.5.1`
- Device: `iPhone Simulator`
- OS: `iOS 17.2`

## Steps to Reproduce
- Navigate to a screen with MapWidget
- Pop the screen with MapWidget
Code: [GitHub Gist](https://gist.github.com/kalucky0/59f2649c482abd94abc5a2a1c78e6d2f)

## Description
I'm encountering an issue where an exception is thrown after exiting a screen and calling `dispose()` on `MapboxMap`. The exception message suggests that the `MapboxMap` object is being used after being disposed.

## Expected Behavior
After calling `dispose()` on a `MapboxMap` object, the object is disposed of properly and no exception is thrown.

## Actual Behavior
The following exception is thrown:

```yaml
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: A MapboxMap was used after being disposed.
Once you have called dispose() on a MapboxMap, it can no longer be used.
#0 ChangeNotifier.debugAssertNotDisposed. (package:flutter/src/foundation/change_notifier.dart:179:9)
#1 ChangeNotifier.debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:186:6)
#2 ChangeNotifier.dispose (package:flutter/src/foundation/change_notifier.dart:375:27)
#3 MapboxMap.dispose (package:mapbox_maps_flutter/src/mapbox_map.dart:194:11)
#4 _MapWidgetState.dispose (package:mapbox_maps_flutter/src/map_widget.dart:208:18)

```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the disposal paths in src/mapbox_maps_flutter/src/mapbox_map.dart and src/mapbox_maps_flutter/src/map_widget.dart, using the linked reproduction steps and Gist to reproduce the failure. Done means popping a screen containing MapWidget and disposing its MapboxMap without the reported use-after-dispose exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, ios
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.