Index: /trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 18939)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 18940)
@@ -147,11 +147,6 @@
         MapFrame map = MainApplication.getMap();
         synchronized (ImageViewerDialog.class) {
-            if (dialog != null) {
-                if (map != null && map.getToggleDialog(ImageViewerDialog.class) != null) {
-                    map.removeToggleDialog(dialog);
-                }
-                if (!dialog.isDestroyed()) {
-                    dialog.destroy();
-                }
+            if (dialog != null && map != null && map.getToggleDialog(ImageViewerDialog.class) != null) {
+                map.removeToggleDialog(dialog);
             }
         }
@@ -303,7 +298,4 @@
         if (geoImageLayers.isEmpty()) {
             this.layers.setVisible(false);
-            hideNotify();
-            if (hasInstance())
-                destroyInstance();
         } else {
             this.layers.setVisible(true);
@@ -430,8 +422,4 @@
     }
 
-    private boolean isDestroyed() {
-        return this.titleBar == null;
-    }
-
     /**
      * This literally exists to silence sonarlint complaints.
@@ -1128,4 +1116,8 @@
         }
         this.updateLayers(true);
+        if (!layers.isVisible()) {
+            hideNotify();
+            destroy();
+        }
     }
 
