[camera] StartImageStream after stopImageStream returns old imageData.

This issue has been created since 2022-11-23.

Description
ImageStream returns old imageData when imageStream is started after stopImageStream call.
This is causing barcode scanner to find the same barcode twice even though user is not pointing the camera towards the barcode for the second time.

Minimal Code Example

// ignore_for_file: avoid_print

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

late List<CameraDescription> _cameras;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  _cameras = await availableCameras();
  runApp(const CameraApp());
}

/// CameraApp is the Main Application.
class CameraApp extends StatefulWidget {
  /// Default Constructor
  const CameraApp({Key? key}) : super(key: key);

  @override
  State<CameraApp> createState() => _CameraAppState();
}

class _CameraAppState extends State<CameraApp> {
  late CameraController controller;

  void _processImageFromStream(CameraImage image) {
    print(image.planes[0].bytes[0]);
  }

  @override
  void initState() {
    super.initState();
    controller = CameraController(_cameras[0], ResolutionPreset.low, enableAudio: false);
    controller.initialize().then((_) {
      if (!mounted) {
        return;
      }
      setState(() {});
    }).catchError((Object e) {
      if (e is CameraException) {
        switch (e.code) {
          case 'CameraAccessDenied':
            print('User denied camera access.');
            break;
          default:
            print('Handle other errors.');
            break;
        }
      }
    });
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    if (!controller.value.isInitialized) {
      return Container();
    }
    return MaterialApp(
        home: Column(children: [
      Expanded(child: CameraPreview(controller)),
      GestureDetector(
          onTap: () {
            if (controller.value.isStreamingImages) {
              print('Stopping image stream');
              controller.stopImageStream();
            } else {
              print('Starting new image stream');
              controller.startImageStream(_processImageFromStream);
            }
          },
          child: Container(color: Colors.green, child: const Text('Start or stop image stream')))
    ]));
  }
}

Affected Camera Plugin Version
camera: 0.10.0+4, also reproducible on older versions

Flutter Doctor Output

[✓] Flutter (Channel stable, 3.3.8, on macOS 13.0.1 22A400 darwin-arm, locale en-IS)
    • Flutter version 3.3.8 on channel stable at /Users/a/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (2 weeks ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/a/Library/Android/sdk
    • Platform android-33, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode-14.1.0.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • 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.11+0-b60-7772763)

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • SM S901B (mobile) • RFCT8032PHN • android-arm64  • Android 13 (API 33)
    • macOS (desktop)   • macos       • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Steps To Reproduce

  1. Point the camera towards light object
  2. Start image stream
  3. Stop the image stream
  4. point camera towards dark object
  5. Start the image stream again
  6. Look at console output

Results

I/flutter (19192): Starting new image stream
I/flutter (19192): 152
I/flutter (19192): 134
I/flutter (19192): 132
I/flutter (19192): 137
I/flutter (19192): 146
I/flutter (19192): 146
I/flutter (19192): 141
I/flutter (19192): 144
I/flutter (19192): Stopping image stream
I/flutter (19192): Starting new image stream
I/flutter (19192): 142
I/flutter (19192): 5
I/flutter (19192): 2
I/flutter (19192): 2
I/flutter (19192): 5
I/flutter (19192): 3
I/flutter (19192): 4
I/flutter (19192): 3
I/flutter (19192): 2
I/flutter (19192): 4
I/flutter (19192): 3
I/flutter (19192): 5
I/flutter (19192): Stopping image stream

Expected Results

I/flutter (19192): Starting new image stream
I/flutter (19192): 152
I/flutter (19192): 134
I/flutter (19192): 132
I/flutter (19192): 137
I/flutter (19192): 146
I/flutter (19192): 146
I/flutter (19192): 141
I/flutter (19192): 144
I/flutter (19192): Stopping image stream
I/flutter (19192): Starting new image stream
I/flutter (19192): 5
I/flutter (19192): 2
I/flutter (19192): 2
I/flutter (19192): 5
I/flutter (19192): 3
I/flutter (19192): 4
I/flutter (19192): 3
I/flutter (19192): 2
I/flutter (19192): 4
I/flutter (19192): 3
I/flutter (19192): 5
I/flutter (19192): Stopping image stream

Device Information
S22(SM-S901B/DS) was used for example above - Android 13 (API 33) - Build number TP1A.220624.014.S901BXXU2BVKB
Reproducible on at least all Android phones I tested, Samsung S22, OnePlus 6, LG K40s, Samsung A12.
Have not been able to produce on IOS.

atlid8 wrote this answer on 2022-11-23

Has never happened on IOS, only reproducible on Android(tested on s22 in the example above, also tested on older LG phone and their I got more then one imageData that was old)

huycozy wrote this answer on 2022-11-24

Hi @atlid8
To be more precise, please provide the information indicated below so that we can verify the issue properly:

Also, you may want to refer to writing and formatting syntax for beautifully formatted issue description.

Thank you!

atlid8 wrote this answer on 2022-11-24

Edit done @huycozy

huycozy wrote this answer on 2022-11-25

@atlid8 thanks for updating the issue with more information. This issue is reproducible on the latest stable and master channels with Pixel 3a, Android 12. Labeling the issue for further insights from the team.

Demo video
Screen.Recording.2022-11-25.at.10.26.46.mp4
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.3.9, on macOS 13.0 22A380 darwin-x64, locale en-VN)
    • Flutter version 3.3.9 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (31 hours ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • 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.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • 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.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 70.0.5
    • Dart plugin version 222.4167.21

[✓] 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.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • SM T225 (mobile) • R9JT3004VRJ • android-arm64  • Android 12 (API 31)
    • macOS (desktop)  • macos       • darwin-x64     • macOS 13.0 22A380 darwin-x64
    • Chrome (web)     • chrome      • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[!] Flutter (Channel master, 3.6.0-7.0.pre.52, on macOS 13.0 22A380 darwin-x64, locale en-VN)
    • Flutter version 3.6.0-7.0.pre.52 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ff59250dbe (4 hours ago), 2022-11-24 18:08:30 -0500
    • Engine revision 7665ae5184
    • Dart version 2.19.0 (build 2.19.0-429.0.dev)
    • DevTools version 2.19.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] 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.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • 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.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 70.0.5
    • Dart plugin version 222.4167.21

[✓] 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.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • Pixel 3a (mobile) • 964AY0WL20 • android-arm64  • Android 12 (API 32)
    • macOS (desktop)   • macos      • darwin-x64     • macOS 13.0 22A380 darwin-x64
    • Chrome (web)      • chrome     • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
reidbaker wrote this answer on 2022-12-01

Assigning to @camsim99. Please as you work on the Camerax migration validate that this bug no longer happens before marking camerax migration done.

If it still happens after the migration add a comment so we can figure out the correct next steps.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-12-10
Star Count 147243
Watcher Count 3561
Fork Count 23950
Issue Count 11325

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Create basic SQL tutorial 1 2022-04-13 2022-11-12
forrtl: severe (124): Invalid command supplied to EXECUTE_COMMAND_LINE 4 2021-10-16 2022-02-21
make crest available in conda 2 2021-10-28 2022-02-21
Reoptimization of CREST ensemble: wrong energies!? 2 2021-11-17 2022-02-21
[Sample Wallet] Crash on session deletions 1 2022-11-14 2022-11-25
Binary only installation does not allow to work with fstab 3 2022-02-01 2022-05-16
[Solved] Missing "padarray.m" when using "getInterTumorHeteroFeature.m" [Solved] 1 2022-07-20 2022-09-23
Opening explorer crashes at a specific position because of a specific game ? 6 2022-11-07 2022-11-21
Migrate from IVsOutputWindow to IOutputChannelStore for writing to the output window 1 2021-03-18 2022-12-06
`-p` shouldn't be required for `-n`, when `--from-url` is given 0 2021-07-11 2022-11-02
JS 函数注释 @return获取不到参数类型 1 2021-05-01 2022-11-06
New Compile Error 10 2021-05-27 2022-01-15
Can't find volk and soapysdr 5 2020-07-20 2022-11-11
How to programmatically call SerenityRunner? 1 2021-08-04 2022-10-12
Not Issue 👉 Few questions 5 2021-09-08 2022-01-02
Newest update causes issues with flux networks 6 2022-10-29 2022-12-06
Support guitablabel and guitabtooltip 1 2019-01-19 2022-12-05
Dual Monitors and Pop-ups 2 2019-11-22 2022-12-04
Stopping other threads because of luckperms plugin 6 2022-11-14 2022-12-01
Error logs in console for no reason, luckperms command doesn't work 3 2022-11-12 2022-12-01
Fedora 34 meshagent 1.0.1 yellow KVM chil process has unexpectedly exited 5 2022-04-04 2022-10-18
SMPEG.DLL in SDL1 have depency to missing LIBSTDC++-6.DLL 6 2022-10-20 2022-11-03
PN532 and ESP8266HTTPClient library incompatibility? 1 2020-06-22 2022-11-27
[11.x] group manager broken in spanish (es_ES) 0 2021-11-18 2022-10-06
为什么用我自己修改过的rrdb用插值会出现如下bug 0 2021-06-24 2022-11-06
Wrong emojis 7 2021-06-20 2022-01-16
Push Based replication rule with a label source filter not working when image retagged 1 2022-06-16 2022-12-03
Download Link Incorrect for QGIS 3.18.3 (MacOS) 1 2021-05-21 2022-10-22
In Data Copy, UseTempDB Causes Timeout after 2 minutes. 5 2022-02-01 2022-10-07
Receiver: instrument multitsdb tenant series tracing tag correctly 5 2021-12-26 2022-12-09
Enable throttling of memory mapping when they are running low on 64-bit systems. 1 2021-10-06 2022-09-27
TS .d file 3 2021-04-19 2021-12-26
Is it possible to feed bound key combinations via stdin? 0 2022-05-29 2022-11-26
$FormatEnumerationLimit triggers PSAvoidGlobalVars warning 4 2021-12-20 2022-11-05
Ternary operators break template subscriptions 2 2022-10-11 2022-10-12
Face Recognition Improvements 2 2021-09-26 2022-10-17
SDK 45 + Dev Client + Android – Unable To Find Development Servers 7 2022-05-28 2022-11-01
Vulkan problem in 4.0 alpha 1 2 2022-01-25 2022-11-05
[BUG] MacOS: frame + roundedcorners prevents fullscreen 2 2022-11-04 2022-11-14
[Bug]: navigator.geolocation.getCurrentPosition() on windows 10 6 2022-11-04 2022-11-14
linear-classify.md typo 0 2022-04-08 2022-11-30
When the working tree/stage is different from the current HEAD commit -> generate SNAPSHOT version 1 2020-06-04 2022-12-08
A question about MaskRCNN with PatchConvNet? 2 2021-12-31 2022-11-28
Unexpected no-cache behavior 1 2022-01-03 2022-10-15
404 error trying to install a Bioconductor package inside the official Bioconductor docker container 5 2022-05-21 2022-11-24
Pop!_Shop shows an odd title when hovering over its window in Gnome 1 2018-11-26 2022-11-13
html-language-features still uses npm in README and launch/tasks 0 2021-11-05 2022-10-04
Sample for CloudWatch Dashboards (Typescript) 1 2021-04-29 2022-10-12
[DataCap Application] 2 2021-11-30 2022-07-26
👑 [需求] 怎么默认选择则菜单第一项 2 2020-07-10 2022-01-23