From f3d47edaac6a16dc91356d89970522ba0c61af8e Mon Sep 17 00:00:00 2001 From: =?utf8?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/Tizen.NUI/src/internal/Interop/Interop.ControlDevel.cs | 3 +++ src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs | 3 +++ .../src/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 07c3da8..f002d0a 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 @@ namespace Tizen.NUI [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 1776e7c..41dbd50 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs @@ -377,6 +377,9 @@ namespace Tizen.NUI.BaseComponents 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 5404598..6b48d1c 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibilityWrappers.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibilityWrappers.cs @@ -53,7 +53,7 @@ namespace Tizen.NUI.BaseComponents 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 @@ namespace Tizen.NUI.BaseComponents 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 @@ namespace Tizen.NUI.BaseComponents private static ulong AccessibilityCalculateStatesWrapper(IntPtr self, ulong initialStates) { View view = GetViewFromRefObject(self); - if (view == null) - return 0UL; ulong bitMask = 0UL; -- 2.7.4