Skip to content

[camera_avfoundation] Use of improperly initialised _lastVideoSampleTime in captureOutput #132014

@misos1

Description

@misos1

Is there an existing issue for this?

Steps to reproduce

Run test code.

Expected results

No crash.

Actual results

Property _lastVideoSampleTime (and also _lastAudioSampleTime) may be improperly initialised when used in CMTimeSubtract which can lead to this exception:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:withPresentationTime:] invalid parameter not satisfying: CMTIME_IS_NUMERIC(presentationTime)'
libc++abi: terminating with uncaught exception of type NSException
* thread #9, queue = 'io.flutter.camera.captureSessionQueue', stop reason = signal SIGABRT

Code sample

Code sample
import "dart:io";
import "package:flutter/material.dart";
import "package:camera/camera.dart";

void main() {
	runApp(const MyApp());
}

class MyApp extends StatelessWidget {
	const MyApp({super.key});
	@override Widget build(BuildContext context) => const MaterialApp(home: MyHomePage());
}

class MyHomePage extends StatefulWidget {
	const MyHomePage({super.key});
	@override State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
	bool loading = true;
	int counter = 0;
	late CameraController camera_cont;

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

	@override void initState() {
		super.initState();
		init_camera();
	}

	init_camera() async {
		final cameras = await availableCameras();
		camera_cont = CameraController(cameras.firstWhere((camera) => camera.lensDirection == CameraLensDirection.back), ResolutionPreset.ultraHigh);
		await camera_cont.initialize();
		setState(() => loading = false);
		await camera_cont.prepareForVideoRecording();
		for(int i = 0; i < 100; i++)
		{
			setState(() => counter = i);
			await camera_cont.startVideoRecording();
			await camera_cont.pauseVideoRecording();
			await camera_cont.resumeVideoRecording();
			await Future.delayed(const Duration(milliseconds: 100));
			final file = await camera_cont.stopVideoRecording();
			await File(file.path).delete();
		}
	}

	@override Widget build(BuildContext context)
	{
		if(loading)return const Center(child: CircularProgressIndicator());
		else return Stack(
			alignment: Alignment.center,
			children: [
				CameraPreview(camera_cont),
				Text("$counter"),
			],
		);
	}
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-x64)

Metadata

Metadata

Assignees

Labels

Bot is counting down the days until it unassigns the issueP2Important issues not at the top of the work listc: fatal crashCrashes that terminate the processfound in release: 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions