From f3d47edaac6a16dc91356d89970522ba0c61af8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20=C5=9Awigo=C5=84?= Date: Thu, 19 Oct 2023 17:53:40 +0200 Subject: [PATCH] [NUI][AT-SPI] Detach NUIViewAccessible in View.Dispose() The application may crash if the View is disposed but the Accessibility infrastructure calls one of the View methods. Detaching the NUIViewAccessible proxy object in View.Dispose() should prevent that. --- .../src/internal/Interop/Interop.ControlDevel.cs | 3 +++ .../src/public/BaseComponents/ViewAccessibility.cs | 3 +++ .../public/BaseComponents/ViewAccessibilityWrappers.cs | 8 ++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.ControlDevel.cs b/src/Tizen.NUI/src/internal/Interop/Interop.ControlDevel.cs index 07c3da8c8e9..f002d0ab7c8 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.ControlDevel.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.ControlDevel.cs @@ -531,6 +531,9 @@ private AccessibilityDelegate() [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Accessibility_SetAccessibilityDelegate")] public static extern IntPtr DaliAccessibilitySetAccessibilityDelegate(IntPtr arg1_accessibilityDelegate, uint arg2_accessibilityDelegateSize); + + [DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Accessibility_DetachAccessibleObject")] + public static extern void DaliAccessibilityDetachAccessibleObject(HandleRef arg1_control); } } } diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs index 1776e7c7499..41dbd50850d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs @@ -377,6 +377,9 @@ protected override void Dispose(bool disposing) internalName = null; + Interop.ControlDevel.DaliAccessibilityDetachAccessibleObject(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + if (disposing == false) { if (IsNativeHandleInvalid() || SwigCMemOwn == false) diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibilityWrappers.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibilityWrappers.cs index 5404598dd24..6b48d1ce160 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibilityWrappers.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibilityWrappers.cs @@ -53,7 +53,7 @@ private static View GetViewFromRefObject(IntPtr refObjectPtr) if (view is null) { - NUILog.Error($"RefObject 0x{refObjectPtr:x} is not a View"); + throw new ArgumentException($"RefObject 0x{refObjectPtr:x} is not a View", nameof(refObjectPtr)); } return view; @@ -70,9 +70,7 @@ private static T GetInterfaceFromRefObject(IntPtr refObjectPtr) return atspiInterface; } - NUILog.Error($"RefObject 0x{refObjectPtr:x} is not a {typeof(T).FullName}"); - - return default(T); + throw new ArgumentException($"RefObject 0x{refObjectPtr:x} is not a {typeof(T).FullName}", nameof(refObjectPtr)); } private static IntPtr DuplicateString(string value) @@ -113,8 +111,6 @@ private static void InitializeAccessibilityDelegateAccessibleInterface() private static ulong AccessibilityCalculateStatesWrapper(IntPtr self, ulong initialStates) { View view = GetViewFromRefObject(self); - if (view == null) - return 0UL; ulong bitMask = 0UL;