From: Artur Świgoń Date: Thu, 19 Oct 2023 15:59:58 +0000 (+0200) Subject: [AT-SPI] Add NUIViewAccessible::Detach() X-Git-Tag: accepted/tizen/unified/20231031.163535~1^2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F300277%2F2;p=platform%2Fcore%2Fuifw%2Fdali-csharp-binder.git [AT-SPI] Add NUIViewAccessible::Detach() 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. Change-Id: I9a86fbda9b1ec6bdb40482195a1541b209b99fcc --- diff --git a/dali-csharp-binder/common/nui-view-accessible.cpp b/dali-csharp-binder/common/nui-view-accessible.cpp index be9a11f3..58e8d2b7 100644 --- a/dali-csharp-binder/common/nui-view-accessible.cpp +++ b/dali-csharp-binder/common/nui-view-accessible.cpp @@ -137,6 +137,11 @@ void NUIViewAccessible::SetAccessibilityDelegate(const AccessibilityDelegate* ac mTable = accessibilityDelegate; } +void NUIViewAccessible::Detach() +{ + mIsDetached = true; +} + std::string NUIViewAccessible::StealString(char* str) { std::string ret{}; @@ -167,6 +172,16 @@ T NUIViewAccessible::StealObject(T* obj) template R NUIViewAccessible::CallMethod(R (*method)(RefObject*, Args...), Args... args) const { + if(mIsDetached) + { + DALI_LOG_ERROR("Method called on detached NUIViewAccessible[%p]", static_cast(this)); + + if constexpr(std::is_same_v) + return; + else + return R{}; + } + DALI_ASSERT_DEBUG(method); DALI_ASSERT_ALWAYS(GetInterfaces()[I]); @@ -718,6 +733,21 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Accessibility_SetAccessibilityDelegate(c })); } +SWIGEXPORT void SWIGSTDCALL CSharp_Dali_Accessibility_DetachAccessibleObject(Dali::Toolkit::Control* arg1_control) +{ + GUARD_ON_NULL_RET(arg1_control); + + try_catch(([&]() { + auto* actorAccessible = Dali::Accessibility::Accessible::Get(*arg1_control); + auto* viewAccessible = dynamic_cast(actorAccessible); + + if(viewAccessible) + { + viewAccessible->Detach(); + } + })); +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/dali-csharp-binder/common/nui-view-accessible.h b/dali-csharp-binder/common/nui-view-accessible.h index 0582a531..f6d09586 100644 --- a/dali-csharp-binder/common/nui-view-accessible.h +++ b/dali-csharp-binder/common/nui-view-accessible.h @@ -53,6 +53,8 @@ public: static void SetAccessibilityDelegate(const AccessibilityDelegate* accessibilityDelegate); + void Detach(); + // Standard interfaces (Accessible, Action, Component) std::string GetNameRaw() const override; @@ -247,6 +249,9 @@ private: */ template R CallMethod(R (*method)(Dali::RefObject*, Args...), Args... args) const; + + // Prevents calling C# methods if the View has been disposed + bool mIsDetached = false; }; #endif // NUI_VIEW_ACCESSIBLE_H