浏览代码

Add parent/automationPeer null guards on AvnWindow (#19805)

* Add parent/automationPeer null guards on AvnWindow

* Add null guards on AvnView
Jumar Macato 1 周之前
父节点
当前提交
67a88afb5d
共有 2 个文件被更改,包括 20 次插入6 次删除
  1. 5 1
      native/Avalonia.Native/src/OSX/AvnView.mm
  2. 15 5
      native/Avalonia.Native/src/OSX/AvnWindow.mm

+ 5 - 1
native/Avalonia.Native/src/OSX/AvnView.mm

@@ -943,7 +943,7 @@ static void ConvertTilt(NSPoint tilt, float* xTilt, float* yTilt)
     auto window = (AvnWindow*)[self window];
     auto peer = [window automationPeer];
 
-    if (!peer->IsRootProvider())
+    if (peer == nullptr || !peer->IsRootProvider())
         return nil;
 
     auto clientPoint = [window convertPointFromScreen:point];
@@ -980,6 +980,10 @@ static void ConvertTilt(NSPoint tilt, float* xTilt, float* yTilt)
     // of the AvnView.
     auto window = (AvnWindow*)[self window];
     auto peer = [window automationPeer];
+    if (peer == nullptr)
+    {
+        return;
+    }
     auto childPeers = peer->GetChildren();
     auto childCount = childPeers != nullptr ? childPeers->GetCount() : 0;
 

+ 15 - 5
native/Avalonia.Native/src/OSX/AvnWindow.mm

@@ -605,21 +605,30 @@
 
 - (id _Nullable) accessibilityFocusedUIElement
 {
-    if (![self automationPeer]->IsRootProvider())
+    auto automationPeer = [self automationPeer];
+    if (automationPeer == nullptr || !automationPeer->IsRootProvider())
         return nil;
-    auto focusedPeer = [self automationPeer]->RootProvider_GetFocus();
+
+    auto focusedPeer = automationPeer->RootProvider_GetFocus();
+    if (focusedPeer == nullptr)
+        return nil;
+
     return [AvnAccessibilityElement acquire:focusedPeer];
 }
 
 - (NSString * _Nullable) accessibilityIdentifier
 {
-    return GetNSStringAndRelease([self automationPeer]->GetAutomationId());
+    auto automationPeer = [self automationPeer];
+    if (automationPeer == nullptr)
+        return nil;
+
+    return GetNSStringAndRelease(automationPeer->GetAutomationId());
 }
 
 - (IAvnAutomationPeer* _Nonnull) automationPeer
 {
     auto parent = _parent.tryGet();
-    if (_automationPeer == nullptr)
+    if (parent && _automationPeer == nullptr)
     {
         _automationPeer = parent->BaseEvents->GetAutomationPeer();
         _automationNode = new AvnAutomationNode(self);
@@ -632,7 +641,8 @@
 - (void)raiseChildrenChanged
 {
     auto parent = _parent.tryGet();
-    [parent->View raiseAccessibilityChildrenChanged];
+    if(parent)
+        [parent->View raiseAccessibilityChildrenChanged];
 }
 
 - (void)raiseFocusChanged