From: dongsug.song Date: Tue, 18 Apr 2023 07:26:24 +0000 (+0900) Subject: [NUI] Add defence codes for specific events X-Git-Tag: submit/tizen_6.0/20230419.023234~1^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7df5b6d1d19cbcccc0be774fd264060263aaea2d;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add defence codes for specific events --- diff --git a/src/Tizen.NUI/src/public/Accessibility/AccessibilityManagerEvent.cs b/src/Tizen.NUI/src/public/Accessibility/AccessibilityManagerEvent.cs index f08d42f55..ad680659a 100755 --- a/src/Tizen.NUI/src/public/Accessibility/AccessibilityManagerEvent.cs +++ b/src/Tizen.NUI/src/public/Accessibility/AccessibilityManagerEvent.cs @@ -1114,23 +1114,28 @@ namespace Tizen.NUI.Accessibility { add { - // Restricted to only one listener if (_accessibilityManagerFocusedViewActivatedEventHandler == null) { - _accessibilityManagerFocusedViewActivatedEventCallbackDelegate = new FocusedViewActivatedEventCallbackDelegate(OnFocusedViewActivated); - this.FocusedViewActivatedSignal().Connect(_accessibilityManagerFocusedViewActivatedEventCallbackDelegate); + _accessibilityManagerFocusedViewActivatedEventCallbackDelegate = OnFocusedViewActivated; + var signal = FocusedViewActivatedSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Connect(_accessibilityManagerFocusedViewActivatedEventCallbackDelegate); + signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - _accessibilityManagerFocusedViewActivatedEventHandler += value; } - remove { _accessibilityManagerFocusedViewActivatedEventHandler -= value; - - if (_accessibilityManagerFocusedViewActivatedEventHandler == null && FocusedViewActivatedSignal().Empty() == false) + if (_accessibilityManagerFocusedViewActivatedEventHandler == null && _accessibilityManagerFocusedViewActivatedEventCallbackDelegate != null) { - this.FocusedViewActivatedSignal().Disconnect(_accessibilityManagerFocusedViewActivatedEventCallbackDelegate); + var signal = FocusedViewActivatedSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_accessibilityManagerFocusedViewActivatedEventCallbackDelegate); + _accessibilityManagerFocusedViewActivatedEventCallbackDelegate = null; + signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } diff --git a/src/Tizen.NUI/src/public/Animation.cs b/src/Tizen.NUI/src/public/Animation.cs index 682f2b43d..71c746c05 100755 --- a/src/Tizen.NUI/src/public/Animation.cs +++ b/src/Tizen.NUI/src/public/Animation.cs @@ -47,6 +47,7 @@ namespace Tizen.NUI private AnimationFinishedEventCallbackType _animationFinishedEventCallback; private System.IntPtr _finishedCallbackOfNative; + private bool isFinishedSignalConnected = false; private AnimationProgressReachedEventCallbackType _animationProgressReachedEventCallback; @@ -74,6 +75,7 @@ namespace Tizen.NUI _animationFinishedEventCallback = OnFinished; _finishedCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(_animationFinishedEventCallback); + isFinishedSignalConnected = false; } [UnmanagedFunctionPointer(CallingConvention.StdCall)] @@ -93,19 +95,28 @@ namespace Tizen.NUI { add { - if (_animationFinishedEventHandler == null && disposed == false) + if (_animationFinishedEventHandler == null && disposed == false && isFinishedSignalConnected == false) { - FinishedSignal().Connect(_finishedCallbackOfNative); + var signal = FinishedSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Connect(_finishedCallbackOfNative); + signal?.Dispose(); + isFinishedSignalConnected = true; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } _animationFinishedEventHandler += value; } remove { _animationFinishedEventHandler -= value; - - if (_animationFinishedEventHandler == null && FinishedSignal().Empty() == false) + if (_animationFinishedEventHandler == null && isFinishedSignalConnected) { - FinishedSignal().Disconnect(_finishedCallbackOfNative); + var signal = FinishedSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_finishedCallbackOfNative); + signal?.Dispose(); + isFinishedSignalConnected = false; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } @@ -1288,10 +1299,15 @@ namespace Tizen.NUI return; } - if (_animationFinishedEventHandler != null) + if (_animationFinishedEventHandler != null && isFinishedSignalConnected) { - FinishedSignal().Disconnect(_finishedCallbackOfNative); + var signal = FinishedSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_finishedCallbackOfNative); + signal?.Dispose(); + isFinishedSignalConnected = false; _animationFinishedEventHandler = null; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } if (_animationProgressReachedEventCallback != null) @@ -1308,7 +1324,7 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) { - if(swigCPtr.Handle == IntPtr.Zero || this.HasBody() == false) + if (swigCPtr.Handle == IntPtr.Zero || this.HasBody() == false) { Tizen.Log.Fatal("NUI", $"[ERROR] Animation ReleaseSwigCPtr()! IntPtr=0x{swigCPtr.Handle:X} HasBody={this.HasBody()}"); return; diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs index 4c15cca7b..bd404a14c 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs @@ -184,23 +184,24 @@ namespace Tizen.NUI.BaseComponents { _keyCallback = OnKeyEvent; var signal = KeyEventSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Connect(_keyCallback); signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } _keyEventHandler += value; } remove { _keyEventHandler -= value; - if (_keyEventHandler == null) + if (_keyEventHandler == null && _keyCallback != null) { var signal = KeyEventSignal(); - if (signal?.Empty() == false) - { - signal?.Disconnect(_keyCallback); - _keyCallback = null; - } + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_keyCallback); + _keyCallback = null; signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } @@ -301,23 +302,24 @@ namespace Tizen.NUI.BaseComponents { _touchDataCallback = OnTouch; var signal = TouchSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Connect(_touchDataCallback); signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } _touchDataEventHandler += value; } remove { _touchDataEventHandler -= value; - if (_touchDataEventHandler == null) + if (_touchDataEventHandler == null && _touchDataCallback != null) { var signal = TouchSignal(); - if (signal?.Empty() == false) - { - signal?.Disconnect(_touchDataCallback); - _touchDataCallback = null; - } + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_touchDataCallback); + _touchDataCallback = null; signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } @@ -449,23 +451,24 @@ namespace Tizen.NUI.BaseComponents { _offWindowEventCallback = OffWindow; var signal = OffWindowSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Connect(_offWindowEventCallback); signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } _offWindowEventHandler += value; } remove { _offWindowEventHandler -= value; - if (_offWindowEventHandler == null) + if (_offWindowEventHandler == null && _offWindowEventCallback != null) { var signal = OffWindowSignal(); - if (signal?.Empty() == false) - { - signal?.Disconnect(_offWindowEventCallback); - _offWindowEventCallback = null; - } + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_offWindowEventCallback); + _offWindowEventCallback = null; signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } @@ -924,7 +927,7 @@ namespace Tizen.NUI.BaseComponents NUILog.Error("implicit disposed(unreachable)! just return here!"); return true; } - + if (touchData == global::System.IntPtr.Zero) { NUILog.Error("touchData should not be null!"); diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index 77113d1ec..59dcd56d3 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -1131,7 +1131,7 @@ namespace Tizen.NUI.BaseComponents //Release your own unmanaged resources here. //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. - + DisConnectFromSignals(); foreach (View view in Children) @@ -1194,9 +1194,11 @@ namespace Tizen.NUI.BaseComponents if (_offWindowEventCallback != null) { ViewSignal signal = new ViewSignal(Interop.ActorSignal.Actor_OffSceneSignal(GetBaseHandleCPtrHandleRef), false); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Disconnect(_offWindowEventCallback); signal?.Dispose(); _offWindowEventCallback = null; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } if (_onWindowEventCallback != null) @@ -1239,9 +1241,11 @@ namespace Tizen.NUI.BaseComponents if (_touchDataCallback != null) { TouchDataSignal signal = new TouchDataSignal(Interop.ActorSignal.Actor_TouchSignal(GetBaseHandleCPtrHandleRef), false); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Disconnect(_touchDataCallback); signal?.Dispose(); _touchDataCallback = null; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } if (_ResourcesLoadedCallback != null) @@ -1255,9 +1259,11 @@ namespace Tizen.NUI.BaseComponents if (_keyCallback != null) { ControlKeySignal signal = new ControlKeySignal(Interop.ViewSignal.View_KeyEventSignal(GetBaseHandleCPtrHandleRef), false); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Disconnect(_keyCallback); signal?.Dispose(); _keyCallback = null; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } if (_keyInputFocusLostCallback != null) diff --git a/src/Tizen.NUI/src/public/PropertyNotification.cs b/src/Tizen.NUI/src/public/PropertyNotification.cs index 6fa83fe65..0763d952f 100755 --- a/src/Tizen.NUI/src/public/PropertyNotification.cs +++ b/src/Tizen.NUI/src/public/PropertyNotification.cs @@ -1,5 +1,5 @@ /* - * Copyright(c) 2019 Samsung Electronics Co., Ltd. + * Copyright(c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,10 +28,12 @@ namespace Tizen.NUI /// 4 public class PropertyNotification : BaseHandle { + #region Fields + private DaliEventHandler notifiedEventHandler; + private NotifyEventCallbackDelegate notifySignalCallback; + #endregion //#region Fields - private DaliEventHandler _propertyNotificationNotifyEventHandler; - private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate; - + #region Constructors /// /// Create a instance of PropertyNotification. /// @@ -53,10 +55,58 @@ namespace Tizen.NUI internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PropertyNotification.PropertyNotification_SWIGUpcast(cPtr), cMemoryOwn) { } + #endregion //#region Constructors + + #region Distructors + /// + /// you can override it to clean-up your own resources. + /// + /// DisposeTypes + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (notifySignalCallback != null) + { + var signal = NotifySignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(notifySignalCallback); + notifySignalCallback = null; + signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + if (type == DisposeTypes.Explicit) + { + //Called by User + //Release your own managed resources here. + //You should release all of your own disposable objects here. + } + //Release your own unmanaged resources here. + //You should not access any managed member here except static instance. + //because the execution order of Finalizes is non-deterministic. + + base.Dispose(type); + } + // This will not be public opened. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) + { + Interop.PropertyNotification.delete_PropertyNotification(swigCPtr); + } + #endregion //#region Distructors + + #region Delegates [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification); + #endregion //#region Delegates + #region Events /// /// Event for Notified signal which can be used to subscribe/unsubscribe the event handler /// Notified signal is emitted when the notification upon a condition of the property being met, has occurred. @@ -66,33 +116,59 @@ namespace Tizen.NUI { add { - lock (this) + if (notifiedEventHandler == null) { - // Restricted to only one listener - if (_propertyNotificationNotifyEventHandler == null) - { - _propertyNotificationNotifyEventHandler += value; - - _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify); - this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate); - } + notifySignalCallback = OnPropertyNotificationNotify; + var signal = NotifySignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Connect(notifySignalCallback); + signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + notifiedEventHandler += value; } - remove { - lock (this) + notifiedEventHandler -= value; + if (notifiedEventHandler == null && notifySignalCallback != null) { - if (_propertyNotificationNotifyEventHandler != null) - { - this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate); - } + var signal = NotifySignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(notifySignalCallback); + notifySignalCallback = null; + signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + } - _propertyNotificationNotifyEventHandler -= value; + /// + /// Event arguments that passed via Notify signal + /// + /// 3 + public class NotifyEventArgs : EventArgs + { + private PropertyNotification propertyNotification; + + /// + /// PropertyNotification - is the PropertyNotification handle that has the notification properties. + /// + /// 3 + public PropertyNotification PropertyNotification + { + get + { + return propertyNotification; + } + set + { + propertyNotification = value; } } } + #endregion //#region Events + #region Enums /// /// Enumeration for description of how to check condition. /// @@ -120,25 +196,9 @@ namespace Tizen.NUI /// 3 NotifyOnChanged } + #endregion //#region Enums - /// - /// Get property notification from Intptr.
- /// This should be internal, please do not use. - ///
- /// An object of IntPtr type. - /// An object of the PropertyNotification type. - /// 4 - [Obsolete("Deprecated in API6, Will be removed in API9, " + - "Please use Notified event instead!" + - "IntPtr(native integer pointer) is supposed to be not used in Application!")] - [EditorBrowsable(EditorBrowsableState.Never)] - public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr) - { - PropertyNotification ret = new PropertyNotification(cPtr, false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - + #region Methods /// /// Downcast a PropertyNotification instance. /// @@ -152,22 +212,6 @@ namespace Tizen.NUI return ret; } - /// - /// Assign. - /// - /// A reference to the copied handle. - /// A reference to this. - /// 4 - [Obsolete("Deprecated in API6, Will be removed in API9, " + - "Please use PropertyNotification() constructor instead!")] - [EditorBrowsable(EditorBrowsableState.Never)] - public PropertyNotification Assign(PropertyNotification rhs) - { - PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.PropertyNotification_Assign(swigCPtr, PropertyNotification.getCPtr(rhs)), false); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - /// /// Gets the condition of this notification. /// @@ -238,12 +282,46 @@ namespace Tizen.NUI return ret; } + /// + /// Get property notification from Intptr.
+ /// This should be internal, please do not use. + ///
+ /// An object of IntPtr type. + /// An object of the PropertyNotification type. + /// 4 + [Obsolete("Deprecated in API6, Will be removed in API9, " + + "Please use Notified event instead!" + + "IntPtr(native integer pointer) is supposed to be not used in Application!")] + [EditorBrowsable(EditorBrowsableState.Never)] + public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr) + { + PropertyNotification ret = new PropertyNotification(cPtr, false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Assign. + /// + /// A reference to the copied handle. + /// A reference to this. + /// 4 + [Obsolete("Deprecated in API6, Will be removed in API9, " + + "Please use PropertyNotification() constructor instead!")] + [EditorBrowsable(EditorBrowsableState.Never)] + public PropertyNotification Assign(PropertyNotification rhs) + { + PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.PropertyNotification_Assign(swigCPtr, PropertyNotification.getCPtr(rhs)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + /// /// Connects to this signal to be notified when the notification has occurred. /// /// A signal object to Connect() with /// 4 - [Obsolete("Deprecated in API6, Will be removed in API9, " + + [Obsolete("Deprecated in API6, Will be removed in API9, " + "Please use Notified event instead!")] [EditorBrowsable(EditorBrowsableState.Never)] public PropertyNotifySignal NotifySignal() @@ -258,49 +336,18 @@ namespace Tizen.NUI return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } - /// This will not be public opened. - [EditorBrowsable(EditorBrowsableState.Never)] - protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) - { - Interop.PropertyNotification.delete_PropertyNotification(swigCPtr); - } - // Callback for PropertyNotification NotifySignal private void OnPropertyNotificationNotify(IntPtr propertyNotification) { NotifyEventArgs e = new NotifyEventArgs(); e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification); - if (_propertyNotificationNotifyEventHandler != null) + if (notifiedEventHandler != null) { //here we send all data to user event handlers - _propertyNotificationNotifyEventHandler(this, e); - } - } - - /// - /// Event arguments that passed via Notify signal - /// - /// 3 - public class NotifyEventArgs : EventArgs - { - private PropertyNotification _propertyNotification; - - /// - /// PropertyNotification - is the PropertyNotification handle that has the notification properties. - /// - /// 3 - public PropertyNotification PropertyNotification - { - get - { - return _propertyNotification; - } - set - { - _propertyNotification = value; - } + notifiedEventHandler(this, e); } } + #endregion //#region Methods } } diff --git a/src/Tizen.NUI/src/public/StyleManager.cs b/src/Tizen.NUI/src/public/StyleManager.cs index 2484c1f2c..af191be85 100755 --- a/src/Tizen.NUI/src/public/StyleManager.cs +++ b/src/Tizen.NUI/src/public/StyleManager.cs @@ -62,17 +62,26 @@ namespace Tizen.NUI { if (_styleManagerStyleChangedEventHandler == null) { - _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged); - StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate); + _styleManagerStyleChangedCallbackDelegate = OnStyleChanged; + var signal = StyleChangedSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Connect(_styleManagerStyleChangedCallbackDelegate); + signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } _styleManagerStyleChangedEventHandler += value; } remove { _styleManagerStyleChangedEventHandler -= value; - if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false) + if (_styleManagerStyleChangedEventHandler == null && _styleManagerStyleChangedCallbackDelegate != null) { - StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate); + var signal = StyleChangedSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_styleManagerStyleChangedCallbackDelegate); + _styleManagerStyleChangedCallbackDelegate = null; + signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } diff --git a/src/Tizen.NUI/src/public/Timer.cs b/src/Tizen.NUI/src/public/Timer.cs index 134d71aa4..2e5bd3510 100755 --- a/src/Tizen.NUI/src/public/Timer.cs +++ b/src/Tizen.NUI/src/public/Timer.cs @@ -40,6 +40,7 @@ namespace Tizen.NUI private TickCallbackDelegate _timerTickCallbackDelegate; private System.IntPtr _timerTickCallbackOfNative; + private bool isTickSignalConnected = false; /// /// Creates a tick timer that emits periodic signal. @@ -60,10 +61,9 @@ namespace Tizen.NUI internal Timer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Timer.Timer_SWIGUpcast(cPtr), cMemoryOwn) { - _timerTickCallbackDelegate = OnTick; _timerTickCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(_timerTickCallbackDelegate); - + isTickSignalConnected = false; NUILog.Debug($"(0x{swigCPtr.Handle:X})Timer() contructor!"); } @@ -87,18 +87,28 @@ namespace Tizen.NUI { add { - if (_timerTickEventHandler == null && disposed == false) + if (_timerTickEventHandler == null && disposed == false && isTickSignalConnected == false) { - TickSignal().Connect(_timerTickCallbackOfNative); + var signal = TickSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Connect(_timerTickCallbackOfNative); + signal?.Dispose(); + isTickSignalConnected = true; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } _timerTickEventHandler += value; } remove { _timerTickEventHandler -= value; - if (_timerTickEventHandler == null && TickSignal().Empty() == false) + if (_timerTickEventHandler == null && isTickSignalConnected) { - TickSignal().Disconnect(_timerTickCallbackOfNative); + var signal = TickSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_timerTickCallbackOfNative); + signal?.Dispose(); + isTickSignalConnected = false; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } @@ -242,7 +252,7 @@ namespace Tizen.NUI internal uint GetInterval() { - if(swigCPtr.Handle == global::System.IntPtr.Zero || disposed) + if (swigCPtr.Handle == global::System.IntPtr.Zero || disposed) { NUILog.Error("[ERR] already disposed! can not get this done! just return here! please make sure that the handle gets free when using explicit Dispose()! For example, timer.Dispose(); timer = null; this must be done!"); return 0; @@ -268,9 +278,14 @@ namespace Tizen.NUI { NUILog.Debug($"(0x{swigCPtr.Handle:X}) Timer.Dispose(type={type}, disposed={disposed})"); - if (this != null && _timerTickCallbackDelegate != null) + if (this != null && _timerTickCallbackDelegate != null && isTickSignalConnected) { - TickSignal().Disconnect(_timerTickCallbackOfNative); + var signal = TickSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_timerTickCallbackOfNative); + signal?.Dispose(); + isTickSignalConnected = false; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } if (disposed) diff --git a/src/Tizen.NUI/src/public/WindowEvent.cs b/src/Tizen.NUI/src/public/WindowEvent.cs index d297fb209..5d635eb94 100755 --- a/src/Tizen.NUI/src/public/WindowEvent.cs +++ b/src/Tizen.NUI/src/public/WindowEvent.cs @@ -110,23 +110,24 @@ namespace Tizen.NUI { _rootLayerTouchDataCallback = OnWindowTouch; var signal = TouchDataSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Connect(_rootLayerTouchDataCallback); signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } _rootLayerTouchDataEventHandler += value; } remove { _rootLayerTouchDataEventHandler -= value; - if (_rootLayerTouchDataEventHandler == null) + if (_rootLayerTouchDataEventHandler == null && _rootLayerTouchDataCallback != null) { var signal = TouchDataSignal(); - if (signal?.Empty() == false) - { - signal?.Disconnect(_rootLayerTouchDataCallback); - _rootLayerTouchDataCallback = null; - } + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_rootLayerTouchDataCallback); + _rootLayerTouchDataCallback = null; signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } @@ -176,23 +177,24 @@ namespace Tizen.NUI { _stageKeyCallbackDelegate = OnStageKey; var signal = KeyEventSignal(); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Connect(_stageKeyCallbackDelegate); signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } _stageKeyHandler += value; } remove { _stageKeyHandler -= value; - if (_stageKeyHandler == null) + if (_stageKeyHandler == null && _stageKeyCallbackDelegate != null) { var signal = KeyEventSignal(); - if (signal?.Empty() == false) - { - signal?.Disconnect(_stageKeyCallbackDelegate); - _stageKeyCallbackDelegate = null; - } + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } + signal?.Disconnect(_stageKeyCallbackDelegate); + _stageKeyCallbackDelegate = null; signal?.Dispose(); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } @@ -577,9 +579,11 @@ namespace Tizen.NUI if (_rootLayerTouchDataCallback != null) { TouchDataSignal signal = new TouchDataSignal(Interop.ActorSignal.Actor_TouchSignal(Layer.getCPtr(GetRootLayer())), false); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Disconnect(_rootLayerTouchDataCallback); signal?.Dispose(); _rootLayerTouchDataCallback = null; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } if (_wheelEventCallback != null) @@ -598,9 +602,11 @@ namespace Tizen.NUI if (_stageKeyCallbackDelegate != null) { KeyEventSignal signal = new KeyEventSignal(Interop.Window.KeyEventSignal(GetBaseHandleCPtrHandleRef), false); + if (signal?.SwigCPtr.Handle == IntPtr.Zero) { signal = null; } signal?.Disconnect(_stageKeyCallbackDelegate); signal?.Dispose(); _stageKeyCallbackDelegate = null; + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } if (_stageEventProcessingFinishedEventCallbackDelegate != null)