Index: includes/behaviors/js/openlayers_behavior_popup.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openlayers/includes/behaviors/js/Attic/openlayers_behavior_popup.js,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 openlayers_behavior_popup.js
--- includes/behaviors/js/openlayers_behavior_popup.js	28 Jun 2010 17:30:19 -0000	1.1.2.4
+++ includes/behaviors/js/openlayers_behavior_popup.js	1 Jan 2011 11:07:40 -0000
@@ -67,15 +67,22 @@ Drupal.behaviors.openlayers_behavior_pop
             null,
             true,
             function (evt) {
-              Drupal.openlayers.popup.popupSelect.unselect(
-                Drupal.openlayers.popup.selectedFeature
-              );
+              var f = Drupal.openlayers.popup.selectedFeature;
+              if (f.layer)
+                Drupal.openlayers.popup.popupSelect.unselect(f);
+              else {
+                // Remove popup if feature was removed in the meantime.
+                f.popup.map.removePopup(f.popup);
+                f.popup.destroy();
+                f.popup = null;
+              }
             }
           );
           
           // Assign popup to feature and map.
           feature.popup = popup;
           feature.layer.map.addPopup(popup);
+          popup.map = feature.layer.map;
           Drupal.openlayers.popup.selectedFeature = feature;
         },
         onUnselect: function (feature) {
