Skip to content

Commit

Permalink
guard against disposed notifications being shown in the first place
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Oct 1, 2024
1 parent a1b1215 commit 51c2358
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions haxe/ui/notifications/NotificationManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,23 @@ class NotificationManager extends EventDispatcher<NotificationEvent> {
var notification = new Notification();
notification.registerEvent(UIEvent.DESTROY, onNotificationDestroyed);
notification.notificationData = notificationData;
Timer.delay(function() {
if (notificationDisplayDelayMs <= 0) {
if (!_isAnimating) {
pushNotification(notification);
} else {
_addQueue.push(notification);
startTimer();
}
}, notificationDisplayDelayMs);
} else {
Timer.delay(function() {
if (!_isAnimating) {
pushNotification(notification);
} else {
_addQueue.push(notification);
startTimer();
}
}, notificationDisplayDelayMs);
}

return notification;
}
Expand Down Expand Up @@ -153,6 +162,10 @@ class NotificationManager extends EventDispatcher<NotificationEvent> {
notification.opacity = 0;
Screen.instance.addComponent(notification);
Toolkit.callLater(function () {
// its possible that in this notification could have been destroyed in this one frame
if (@:privateAccess notification._isDisposed) {
return;
}
notification.validateNow();
var scx = Screen.instance.width;
var scy = Screen.instance.height;
Expand All @@ -176,6 +189,10 @@ class NotificationManager extends EventDispatcher<NotificationEvent> {

if (notification.notificationData.expiryMs > 0) {
Timer.delay(function () {
// its possible that in this notification could have been destroyed in this time
if (@:privateAccess notification._isDisposed) {
return;
}
removeNotification(notification);
}, notification.notificationData.expiryMs);
}
Expand Down

0 comments on commit 51c2358

Please sign in to comment.