From c84b9283be312c26e3482e0c6cb1bebbb1459b0b Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Mon, 18 Mar 2024 11:39:51 +0700 Subject: [PATCH] Ignore calls on onViewDetachedPrivate if view was not attached yet. Add check if root scene is not null in case of overlays --- .../src/main/java/bisq/desktop/common/view/View.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/common/view/View.java b/apps/desktop/desktop/src/main/java/bisq/desktop/common/view/View.java index f9891dcaf4..50976fcc0e 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/common/view/View.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/common/view/View.java @@ -34,6 +34,7 @@ public abstract class View sceneChangeListener; private ChangeListener windowChangeListener; + private boolean isViewAttached; public View(R root, M model, C controller) { checkNotNull(root, "Root must not be null"); @@ -55,7 +56,8 @@ private void handleSceneChange(Scene oldValue, Scene newScene) { } else { // For overlays, we need to wait until window is available windowChangeListener = (observable, oldWindow, newWindow) -> { - if (newWindow != null) { + // As we get called with a delay it might be that the root scene has already changed to null. + if (newWindow != null && root.getScene() != null) { onViewAttachedPrivate(); } else { onViewDetachedPrivate(); @@ -82,8 +84,14 @@ public R getRoot() { } private void onViewDetachedPrivate() { + // In case we have an overlay we might get called before the onViewAttachedPrivate was called in the windowChangeListener + // We avoid that call as it could lead to null pointers in the onViewDetached methods. + if (!isViewAttached) { + return; + } controller.onDeactivateInternal(); onViewDetachedInternal(); + isViewAttached = false; } private void onViewAttachedPrivate() { @@ -91,6 +99,7 @@ private void onViewAttachedPrivate() { // correct state. controller.onActivateInternal(); onViewAttachedInternal(); + isViewAttached = true; } // The internal methods should be only used by framework classes (e.g. TabView)