Skip to content

Commit

Permalink
Add guard for window callbacks to check disposal
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyun Yang <[email protected]>
  • Loading branch information
rabbitfor authored and dongsug-song committed Dec 9, 2024
1 parent 89069ed commit c7271b1
Showing 1 changed file with 96 additions and 11 deletions.
107 changes: 96 additions & 11 deletions src/Tizen.NUI/src/public/Window/WindowEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,11 @@ internal void DisconnectNativeSignals()

private void OnWindowFocusedChanged(IntPtr window, bool focusGained)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == IntPtr.Zero)
{
NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
Expand All @@ -1053,7 +1058,7 @@ private void OnWindowFocusedChanged(IntPtr window, bool focusGained)

private bool OnWindowTouch(IntPtr view, IntPtr touchData)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return false;
Expand All @@ -1076,7 +1081,7 @@ private bool OnWindowTouch(IntPtr view, IntPtr touchData)

private bool OnWindowInterceptTouch(IntPtr view, IntPtr touchData)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return false;
Expand All @@ -1100,7 +1105,7 @@ private bool OnWindowInterceptTouch(IntPtr view, IntPtr touchData)

private bool OnStageWheel(IntPtr rootLayer, IntPtr wheelEvent)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return false;
Expand All @@ -1123,7 +1128,7 @@ private bool OnStageWheel(IntPtr rootLayer, IntPtr wheelEvent)

private bool OnWindowInterceptWheel(IntPtr view, IntPtr wheelEvent)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return false;
Expand All @@ -1148,7 +1153,7 @@ private bool OnWindowInterceptWheel(IntPtr view, IntPtr wheelEvent)
// Callback for Stage KeyEventsignal
private void OnStageKey(IntPtr data)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return;
Expand All @@ -1166,7 +1171,7 @@ private void OnStageKey(IntPtr data)
// Callback for Stage InterceptKeyEventsignal
private bool OnStageInterceptKey(IntPtr data)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return false;
Expand All @@ -1186,29 +1191,54 @@ private bool OnStageInterceptKey(IntPtr data)
// Callback for Stage EventProcessingFinishedSignal
private void OnEventProcessingFinished()
{
if (IsDisposedOrQueued)
{
return;
}

stageEventProcessingFinishedEventHandler?.Invoke(this, null);
}

// Callback for Stage ContextLostSignal
private void OnContextLost()
{
if (IsDisposedOrQueued)
{
return;
}

stageContextLostEventHandler?.Invoke(this, null);
}

// Callback for Stage ContextRegainedSignal
private void OnContextRegained()
{
if (IsDisposedOrQueued)
{
return;
}

stageContextRegainedEventHandler?.Invoke(this, null);
}

// Callback for Stage SceneCreatedSignal
private void OnSceneCreated()
{
if (IsDisposedOrQueued)
{
return;
}

stageSceneCreatedEventHandler?.Invoke(this, null);
}

private void OnResized(IntPtr window, IntPtr windowSize)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == IntPtr.Zero)
{
NUILog.Error("OnResized() Window is null! Do nothing!");
Expand All @@ -1232,6 +1262,11 @@ private void OnResized(IntPtr window, IntPtr windowSize)

private void OnWindowFocusedChanged2(IntPtr window, bool focusGained)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == IntPtr.Zero)
{
NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
Expand All @@ -1248,6 +1283,11 @@ private void OnWindowFocusedChanged2(IntPtr window, bool focusGained)

private void OnTransitionEffect(IntPtr window, int state, int type)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == global::System.IntPtr.Zero)
{
return;
Expand All @@ -1265,6 +1305,11 @@ private void OnTransitionEffect(IntPtr window, int state, int type)

private void OnMoved(IntPtr window, IntPtr position)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == global::System.IntPtr.Zero)
{
return;
Expand All @@ -1281,6 +1326,11 @@ private void OnMoved(IntPtr window, IntPtr position)

private void OnOrientationChanged(IntPtr window, int orientation)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == global::System.IntPtr.Zero)
{
return;
Expand All @@ -1297,13 +1347,18 @@ private void OnOrientationChanged(IntPtr window, int orientation)

private void OnKeyboardRepeatSettingsChanged()
{
if (IsDisposedOrQueued)
{
return;
}

keyboardRepeatSettingsChangedHandler?.Invoke(this, null);
return;
}

private void OnWindowMouseInOutEvent(IntPtr view, IntPtr mouseEvent)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return;
Expand All @@ -1325,6 +1380,11 @@ private void OnWindowMouseInOutEvent(IntPtr view, IntPtr mouseEvent)

private void OnMoveCompleted(IntPtr window, IntPtr position)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == global::System.IntPtr.Zero)
{
return;
Expand All @@ -1340,6 +1400,11 @@ private void OnMoveCompleted(IntPtr window, IntPtr position)

private void OnResizeCompleted(IntPtr window, IntPtr size)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == global::System.IntPtr.Zero)
{
return;
Expand All @@ -1355,7 +1420,7 @@ private void OnResizeCompleted(IntPtr window, IntPtr size)

private void OnWindowMouseRelativeEvent(IntPtr view, IntPtr mouseEvent)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return;
Expand All @@ -1377,7 +1442,7 @@ private void OnWindowMouseRelativeEvent(IntPtr view, IntPtr mouseEvent)

private void OnWindowPointerConstraintsEvent(IntPtr view, IntPtr constraintsEvent)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return;
Expand All @@ -1399,7 +1464,7 @@ private void OnWindowPointerConstraintsEvent(IntPtr view, IntPtr constraintsEven

private bool OnWindowHover(IntPtr view, IntPtr hoverData)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return false;
Expand Down Expand Up @@ -1749,7 +1814,7 @@ public EffectType Type

private void OnDetentEvent(IntPtr wheelEvent)
{
if (Disposed || IsDisposeQueued)
if (IsDisposedOrQueued)
{
// Ignore native callback if the window is disposed or queued for disposal.
return;
Expand Down Expand Up @@ -1788,6 +1853,11 @@ public bool Visibility

private void OnVisibilityChanged(IntPtr window, bool visibility)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == global::System.IntPtr.Zero)
{
NUILog.Error("[ERR] OnVisibilityChanged() window is null");
Expand Down Expand Up @@ -1851,6 +1921,11 @@ public void VisibiltyChangedSignalEmit(bool visibility)

private void OnAuxiliaryMessage(IntPtr kData, IntPtr vData, IntPtr optionsArray)
{
if (IsDisposedOrQueued)
{
return;
}

if (kData == IntPtr.Zero || vData == IntPtr.Zero)
{
return;
Expand Down Expand Up @@ -1984,6 +2059,11 @@ internal set

private void OnInsetsChanged(int partType, int partState, IntPtr extents)
{
if (IsDisposedOrQueued)
{
return;
}

if (insetsChangedEventHandler != null)
{
InsetsChangedEventArgs e = new InsetsChangedEventArgs();
Expand Down Expand Up @@ -2046,6 +2126,11 @@ public bool AccessibilityHighlight

private void OnAccessibilityHighlight(IntPtr window, bool highlight)
{
if (IsDisposedOrQueued)
{
return;
}

if (window == global::System.IntPtr.Zero)
{
NUILog.Error("[ERR] OnAccessibilityHighlight() window is null");
Expand Down

0 comments on commit c7271b1

Please sign in to comment.