This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[camera]fix crash due to race condition in dispatch queue (#4619)
- Loading branch information
1 parent
4d8e98d
commit 6524fb6
Showing
6 changed files
with
57 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/camera/camera/example/ios/RunnerTests/CameraCaptureSessionQueueRaceConditionTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
@import camera; | ||
@import camera.Test; | ||
@import XCTest; | ||
|
||
@interface CameraCaptureSessionQueueRaceConditionTests : XCTestCase | ||
@end | ||
|
||
@implementation CameraCaptureSessionQueueRaceConditionTests | ||
|
||
- (void)testFixForCaptureSessionQueueNullPointerCrashDueToRaceCondition { | ||
CameraPlugin *camera = [[CameraPlugin alloc] initWithRegistry:nil messenger:nil]; | ||
|
||
XCTestExpectation *disposeExpectation = | ||
[self expectationWithDescription:@"dispose's result block must be called"]; | ||
XCTestExpectation *createExpectation = | ||
[self expectationWithDescription:@"create's result block must be called"]; | ||
FlutterMethodCall *disposeCall = [FlutterMethodCall methodCallWithMethodName:@"dispose" | ||
arguments:nil]; | ||
FlutterMethodCall *createCall = [FlutterMethodCall | ||
methodCallWithMethodName:@"create" | ||
arguments:@{@"resolutionPreset" : @"medium", @"enableAudio" : @(1)}]; | ||
// Mimic a dispose call followed by a create call, which can be triggered by slightly dragging the | ||
// home bar, causing the app to be inactive, and immediately regain active. | ||
[camera handleMethodCall:disposeCall | ||
result:^(id _Nullable result) { | ||
[disposeExpectation fulfill]; | ||
}]; | ||
[camera handleMethodCall:createCall | ||
result:^(id _Nullable result) { | ||
[createExpectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:1 handler:nil]; | ||
// `captureSessionQueue` must not be nil after `create` call. Otherwise a nil | ||
// `captureSessionQueue` passed into `AVCaptureVideoDataOutput::setSampleBufferDelegate:queue:` | ||
// API will cause a crash. | ||
XCTAssertNotNil(camera.captureSessionQueue, | ||
@"captureSessionQueue must not be nil after create method. "); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters