-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
c: crashStack traces logged to the consoleStack traces logged to the consolec: fatal crashCrashes that terminate the processCrashes that terminate the processfound in release: 1.22Found to occur in 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginThe camera pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallywaiting for PR to land (fixed)A fix is in flightA fix is in flight
Description
Crash when trying to use the inner camera on Android Pixel 3 XL.
- camera: 0.6.4+5
- Pixel 3 XL android-arm64 Android 11 (API 30)
with 0.6.3+2 works, with 0.6.4+3 crashes.
Steps to Reproduce
- Run following code on Pixel 3 XL
Then it crashes.
code
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
List<CameraDescription> cameras;
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
const MyApp({
Key key,
}) : super(key: key);
@override
State<StatefulWidget> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp>
with WidgetsBindingObserver, TickerProviderStateMixin {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
CameraController controller;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
Future.microtask(() {
availableCameras().then((value) {
cameras = value;
if (controller == null) {
final camera = _selectDefaultCamera(cameras);
onNewCameraSelected(camera);
}
});
});
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
// App state changed before we got the chance to initialize.
if (controller == null || !controller.value.isInitialized) {
return;
}
if (state == AppLifecycleState.inactive) {
controller?.dispose();
} else if (state == AppLifecycleState.resumed) {
if (controller != null) {
onNewCameraSelected(controller.description);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: const Text('Camera example'),
),
body: Column(
children: <Widget>[
Expanded(
child: Container(
color: Colors.black,
padding: const EdgeInsets.all(1.0),
child: Center(
child: _cameraPreviewWidget(),
),
),
),
],
),
);
}
Widget _cameraPreviewWidget() {
if (controller == null) {
return const CircularProgressIndicator();
}else if (!controller.value.isInitialized) {
return const CircularProgressIndicator();
} else {
return CameraPreview(controller);
}
}
void showInSnackBar(String message) {
// ignore: deprecated_member_use
_scaffoldKey.currentState.showSnackBar(SnackBar(content: Text(message)));
}
Future<void> onNewCameraSelected(CameraDescription cameraDescription) async {
if (controller != null) {
final ctrl = controller;
setState(() {
controller = null;
});
await ctrl.dispose();
}
controller = CameraController(
cameraDescription,
ResolutionPreset.medium,
enableAudio: false,
);
// If the controller is updated then update the UI.
controller.addListener(() {
if (mounted) {
setState(() {});
}
if (controller.value.hasError) {
showInSnackBar('Camera error ${controller.value.errorDescription}');
}
});
try {
await controller.initialize();
} on CameraException catch (e) {
print(e);
}
if (mounted) {
setState(() {});
}
}
}
CameraDescription _selectDefaultCamera(List<CameraDescription> cameras) {
for (final camera in cameras) {
if (camera.lensDirection == CameraLensDirection.front) {
return camera;
}
}
return cameras[0];
}Info
D/AndroidRuntime(21322): Shutting down VM
E/AndroidRuntime(21322): FATAL EXCEPTION: main
E/AndroidRuntime(21322): Process: com.example.myapp, PID: 21322
E/AndroidRuntime(21322): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.hardware.camera2.CaptureRequest$Builder.get(android.hardware.camera2.CaptureRequest$Key)' on a null object reference
E/AndroidRuntime(21322): at io.flutter.plugins.camera.Camera.getRegionBoundaries(Camera.java:794)
E/AndroidRuntime(21322): at io.flutter.plugins.camera.Camera.access$300(Camera.java:69)
E/AndroidRuntime(21322): at io.flutter.plugins.camera.Camera$2.onOpened(Camera.java:203)
E/AndroidRuntime(21322): at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:151)
E/AndroidRuntime(21322): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(21322): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(21322): at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime(21322): at android.app.ActivityThread.main(ActivityThread.java:7660)
E/AndroidRuntime(21322): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(21322): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime(21322): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process (21322): Sending signal. PID: 21322 SIG: 9
[✓] Flutter (Channel beta, 1.25.0-8.1.pre, on macOS 11.1 20C69 darwin-arm, locale ja-JP)
• Flutter version 1.25.0-8.1.pre at /Applications/flutter
• Framework revision 8f89f6505b (4 weeks ago), 2020-12-15 15:07:52 -0800
• Engine revision 92ae191c17
• Dart version 2.12.0 (build 2.12.0-133.2.beta)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/najeira/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Users/najeira/Library/Android/sdk
• Java binary at: /Users/najeira/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6953283/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.3, Build version 12C33
• CocoaPods version 1.10.0
[✓] Android Studio (version 4.1)
• Android Studio at /Users/najeira/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.6953283/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 1.8.0_242-release-1644-b3-6915495)
[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.1)
• IntelliJ at /Users/najeira/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
• Flutter plugin version 52.1.5
• Dart plugin version 203.6912
[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.18.1
Metadata
Metadata
Assignees
Labels
c: crashStack traces logged to the consoleStack traces logged to the consolec: fatal crashCrashes that terminate the processCrashes that terminate the processfound in release: 1.22Found to occur in 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginThe camera pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallywaiting for PR to land (fixed)A fix is in flightA fix is in flight