-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Flutter 3] Null pointer dereference in libmapbox-gl.so #107297
Comments
Hi @AAverin Tested on devices:
DemoScreen.Recording.2022-07-11.at.10.31.19.mp4Screen.Recording.2022-07-11.at.10.38.22.movflutter doctor -v[✓] Flutter (Channel stable, 3.0.4, on macOS 12.2.1 21D62 darwin-x64, locale en-VN)
• Flutter version 3.0.4 at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 85684f9300 (3 days ago), 2022-06-30 13:22:47 -0700
• Engine revision 6ba2af10bb
• Dart version 2.17.5
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-33, build-tools 31.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio
• Android Studio at /Applications/Android Studio Preview.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] IntelliJ IDEA Community Edition (version 2020.3.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
• IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.68.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.42.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.53
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category. [✓] Flutter (Channel master, 3.1.0-0.0.pre.1591, on macOS 12.2.1 21D62 darwin-x64, locale en-VN)
• Flutter version 3.1.0-0.0.pre.1591 on channel master at /Users/huynq/Documents/GitHub/flutter_master
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 8d4cad8149 (87 minutes ago), 2022-07-10 21:20:06 -0400
• Engine revision 15402b25b0
• Dart version 2.18.0 (build 2.18.0-271.0.dev)
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-33, build-tools 31.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 13E113
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] IntelliJ IDEA Community Edition (version 2020.3.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
• IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.68.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.44.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found! Does this issue happen on Flutter stable |
Also couldn't reproduce on |
I am still getting the crash on the latest version of Flutter master, usually on hot reload. Will see if find a way to reproduce on a sample somehow. |
The issue looks to be related to the creation of a new instance of the plugin. |
There are many changes that are updated every day. So it's pretty hard to find the PR that fixed this. But if it has improved on master, please try again and again to make sure the issue is fixed. Anyway, I'd love to hear your feedback. |
@huycozy |
@flutter-symbolizer-bot #107297 (comment) flutter#v3.1.0-0.0.pre.1542 debug arm64 |
crash from #107297 (comment) symbolized using symbols for
|
I still can not reproduce the issue on the latest DemoScreen.Recording.2022-07-18.at.09.36.01.mp4flutter doctor -v[✓] Flutter (Channel stable, 3.0.5, on macOS 12.2.1 21D62 darwin-x64, locale en-VN)
• Flutter version 3.0.5 at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f1875d570e (9 hours ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-33, build-tools 31.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] IntelliJ IDEA Community Edition (version 2020.3.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
• IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.69.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.44.0
[✓] Connected device (3 available)
• SM T225 (mobile) • R9JT3004VRJ • android-arm64 • Android 11 (API 30)
• macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
[✓] Flutter (Channel master, 3.1.0-0.0.pre.1698, on macOS 12.2.1 21D62 darwin-x64, locale en-VN)
• Flutter version 3.1.0-0.0.pre.1698 on channel master at /Users/huynq/Documents/GitHub/flutter_master
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision a4ba62fd9d (17 hours ago), 2022-07-17 05:48:06 -0400
• Engine revision b438edfd1a
• Dart version 2.19.0 (build 2.19.0-5.0.dev)
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-33, build-tools 31.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 13E113
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] IntelliJ IDEA Community Edition (version 2020.3.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
• IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.69.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.44.0
[✓] Connected device (3 available)
• SM T225 (mobile) • R9JT3004VRJ • android-arm64 • Android 11 (API 30)
• macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found! It looks like you're testing on an emulator device. Could you retry on a physical device instead to see if the issue still reproduces? |
Sorry for the delay, I will run some more tests once I am back home after vacation next week. |
I have the same issue. When I switch between screens very fast, after a few repeats I manage to crash my app. Example code:import 'package:flutter/material.dart';
import 'package:mapbox_gl/mapbox_gl.dart';
void main() {
runApp(const MapTest());
}
class MapTest extends StatelessWidget {
const MapTest({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MapTest',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: [
IconButton(
icon: const Icon(Icons.map),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const MapScreen(),
),
);
}
),
],
),
body: const Center(child: Icon(Icons.home, size: 50)),
);
}
}
class MapScreen extends StatefulWidget {
const MapScreen({super.key});
@override
State<MapScreen> createState() => _MapScreenState();
}
class _MapScreenState extends State<MapScreen> {
late MapboxMapController mapController;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: [
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.home),
),
],
),
body: MapboxMap(
accessToken: const String.fromEnvironment('SDK_REGISTRY_TOKEN'),
initialCameraPosition: const CameraPosition(target: LatLng(0, 0)),
onMapCreated: _onMapCreated,
),
);
}
Future<void> _onMapCreated(MapboxMapController controller) async {
mapController = controller;
}
} Mapbox version: 0.16.0 flutter doctor -v output:
|
Same issue here, also with mapbox :/ |
I've been working on that problem quite a long time and did not managed to solve it. I've thought that newest version on flutter might help with that but it did no changes with that case at all. It would be helpful if someone could find a workaround for this problem. |
Mapbox Andorid SDK that Mapbox Flutter is using at the moment is not supported anymore, so recompiling the plugin is not an option. |
Any possibility it's related to what was stated here? |
Hi @AAverin and anyone else facing this issue, there is a new beta release: |
Mapbox is using SurfaceAndroidViewController for hybrid composition: https://github.com/flutter-mapbox-gl/maps/blob/3496907955cd4b442e4eb905d67e8d46692174f1/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart#L160 |
For anyone interested in making progress on this issue, the most useful next step would be to bisect versions of Flutter This doesn't require any specific expertise, just a reproduction case and some time to devote to trying lots of builds. |
There's also this workaround, use at your own risk: flutter-mapbox-gl/maps#1172 |
same issue, try mapbox_gl_modified new package. work for me |
@stuartmorgan
You can see our example in this repository: I created multiple branches for the different flutter verisons: Steps to reproduce the crash:
We did the exact same with the native android example app (can be found in the maplibre-gl-native repo) and we didn't see any problems. |
I did a bisect of all the commits between 2.10.5 and 3.10.0: This commit was the "bad" one:
Which corresponds to this engine commit: |
@johnmccutchan I see that you assigned yourself to the issue. |
Thanks @JulianBissekkou for finding the root cause commit to the engine repository. I will look into this next. |
Thank you for the reproduction, I am able to get it to crash. |
So whats the final decision? Should i migrate to a new dependencies like mapbox_maps_flutter? |
@fatihmerickoc |
https://github.com/flutter-mapbox-gl/maps already has the fix implemented too (flutter-mapbox-gl/maps#1293). |
This PR should fix the crash as described in #182 and #257 The status is still in draft because I would like to get feedback from android devs of maplibre-gl-native. ### Problem The crash started to occure with flutter 3.x and after some investigations we were able to detect the exact change that broke it. See flutter/flutter#107297 or flutter/flutter#107297 (comment) for details. The engine change in flutter/engine@8dc7cd1 is not calling `removeView` in all cases which might be the reason why this issue is happening. I digged into the framework and saw that `removeView` will trigger `onDetachedFromWindow` in the subviews. This is important since once of the subviews is `TextureView` which destorys the surface texture: Here is `TextureView.onDeatachedFromWindowInternal` ```java @OverRide @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) protected void onDetachedFromWindowInternal() { destroyHardwareLayer(); releaseSurfaceTexture(); super.onDetachedFromWindowInternal(); } ``` My guess: If this is not called we might still draw onto a surface which triggers the crash. ### The fix If my assumptions are correct then this should be fixed in the engine and not in the libraries that need a platform view. You can find the workaround in this PR. We simply create a view container that calls `removeView` to trigger the `onDetachedFromWindow`. We tested this in an example app with success and also in some of our internal projects. Please give some feedback if my assumptions are correct. Thanks! --------- Co-authored-by: Julian Bissekkou <[email protected]> Co-authored-by: Stefan Schaller <[email protected]>
I actually have not been able to reproduce the null pointer crash. I keep getting heap corruption in the emulator. Still trying to reproduce. |
I was able to reproduce the null pointer crash:
|
@JulianBissekkou Could you confirm that you don't see the crash with flutter/engine#43423 applied? |
…43423) Eagerly remove the PlatformView from the view hierarchy on Android. Fixes [#107297](flutter/flutter#107297) ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing.
@johnmccutchan Do you know if this addresses the Flutter-side regression in #105965 as well? (There was an underlying bug in Google Maps that has been fixed, but it started happening a lot more in Flutter 3, and the crash has similar characteristics.) |
@johnmccutchan |
The situation with the mapbox plugin was the same as well. The crash was already happening in old versions, but very rarely. It's was fixed by disposing the map differently. |
@felix-ht Can you point me at the PR that fixed how the map was disposed in the mapbox plugin? I'd like to read them. |
@felix-ht |
@johnmccutchan flutter-mapbox-gl/maps#1293 -> changes to android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java I am under the impression that the onStop is faster than the onDestroy, and thus stops the java code from drawing after the android view has already been destroyed. But this is just an assumption as i know nearly nothing about the inner workings of the native java/c++ stack of mapbox. Here is also a link to the android lib we use in the background: |
…lutter#43423) Eagerly remove the PlatformView from the view hierarchy on Android. Fixes [#107297](flutter/flutter#107297) ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
I am looking for some help debugging a new critical native crash that affects Mapbox Flutter plugin.
The issue doesn't reproduce on Flutter 2.13 and is only present in Flutter 3.x. No changes to the way plugin was integrated were made and no changes to the native code that plugin relies on were made. The only change was upgrade to Flutter 3.
I have checked the changes done in Flutter engine between 2.13 and 3.0 releases and it's only dart revision: https://github.com/flutter/engine/compare/3096903c8923608d3c1ccf8058a29c31a2bfbc53..d1b9a6938ad77326ac3a94d92bbc77933ed829ed.
Any insight on where to dig?
Steps to Reproduce
flutter run
on the code sampleExpected results:
App shouldn't crash
Actual results:
App crashes with native crash that doesn't happen in Flutter 2.13
Code sample
https://github.com/flutter-mapbox-gl/maps/tree/master/exampleFollow readme instructions on how to run mapbox example app
Logs
The text was updated successfully, but these errors were encountered: