fix crash SemanticsObject dealloc and access the children (flutter/engine#27786)
This commit is contained in:
@@ -372,6 +372,7 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
@implementation SemanticsObject {
|
||||
fml::scoped_nsobject<SemanticsObjectContainer> _container;
|
||||
NSMutableArray<SemanticsObject*>* _children;
|
||||
BOOL _inDealloc;
|
||||
}
|
||||
|
||||
#pragma mark - Override base class designated initializers
|
||||
@@ -413,6 +414,7 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
_parent = nil;
|
||||
_container.get().semanticsObject = nil;
|
||||
[_platformViewSemanticsContainer release];
|
||||
_inDealloc = YES;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -686,6 +688,14 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
}
|
||||
|
||||
- (id)accessibilityContainer {
|
||||
if (_inDealloc) {
|
||||
// In iOS9, `accessibilityContainer` will be called by `[UIAccessibilityElementSuperCategory
|
||||
// dealloc]` during `[super dealloc]`. And will crash when accessing `_children` which has
|
||||
// called `[_children release]` in `[SemanticsObject dealloc]`.
|
||||
// https://github.com/flutter/flutter/issues/87247
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (![self isAccessibilityBridgeAlive]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -644,6 +644,20 @@ class MockAccessibilityBridge : public AccessibilityBridgeIos {
|
||||
XCTAssertEqual(object.accessibilityValue, nativeSwitch.accessibilityValue);
|
||||
}
|
||||
|
||||
- (void)testSemanticsObjectDeallocated {
|
||||
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
|
||||
new flutter::MockAccessibilityBridge());
|
||||
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
|
||||
SemanticsObject* parent = [[SemanticsObject alloc] initWithBridge:bridge uid:0];
|
||||
SemanticsObject* child = [[SemanticsObject alloc] initWithBridge:bridge uid:1];
|
||||
parent.children = @[ child ];
|
||||
// Validate SemanticsObject deallocation does not crash.
|
||||
// https://github.com/flutter/flutter/issues/66032
|
||||
__weak SemanticsObject* weakObject = parent;
|
||||
parent = nil;
|
||||
XCTAssertNil(weakObject);
|
||||
}
|
||||
|
||||
- (void)testFlutterSemanticsObjectReturnsNilContainerWhenBridgeIsNotAlive {
|
||||
FlutterSemanticsObject* parentObject;
|
||||
FlutterSemanticsObject* delegate;
|
||||
|
||||
Reference in New Issue
Block a user