From 7e0da6f21e13dbd7fc10fbba58959ce46ffb5dd6 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] 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 7d74439..f273081 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.ControlDevel.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.ControlDevel.cs @@ -539,6 +539,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 31756b0..5dead25 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs @@ -397,6 +397,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