Index: composite.module
===================================================================
--- composite.module	(revision 1360)
+++ composite.module	(working copy)
@@ -572,6 +572,9 @@
   }
 
   $result = db_query("SELECT type, weight, id, data, zone FROM {node_composite_references} WHERE vid = %d", $node->vid);
+
+  $node_type = content_types($node->type);
+  $warnings = FALSE;
   while ($object = db_fetch_object($result)) {
     // Some common manipulations
     $object = (array) $object;
@@ -580,8 +583,24 @@
     // Some type specific manipulations
     composite_invoke_referenceapi($object, 'load');
 
-    $additions['composite_references'][$object['id']] = $object;
-    $sublists[$object['type']][$object['id']] = $object;
+    $add_object = TRUE;
+    //if the current reference concerns a field of type noderef which references a non-existing node, we do not add it
+    if ($node_type['fields'][$object['parent_field']]['type'] == "nodereference") {
+      $node_type_field = $object['parent_field'];
+      $node_field = $node->$node_type_field;
+      $nid = $node_field[$object['delta']]['nid'];
+      if (!_composite_node_exists($nid)) {
+        $add_object = FALSE;
+        $warnings = TRUE;
+      }
+    }
+    if ($add_object) {
+      $additions['composite_references'][$object['id']] = $object;
+      $sublists[$object['type']][$object['id']] = $object;
+    }
+  }
+  if ($warnings) {
+    _composite_node_warning($node);
   }
 
   // Add reference sublists to the load
@@ -1038,3 +1057,34 @@
   }
 }
 
+/**
+ * Check node exists. Replacement for node_load() in case of possible
+ * recursion.
+ *
+ * @param object|int $node
+ *   Node or nid to check existence.
+ *
+ * @return boolean
+ */
+function _composite_node_exists($node) {
+  $nid = is_object($node) ? $node->nid : $node;
+  return (bool) db_result(db_query("SELECT 1 FROM {node} WHERE nid = %d", $nid));
+}
+
+/**
+ * Display a warning about deleted nodes.
+ */
+function _composite_node_warning($node = NULL) {
+  static $displayed = FALSE;
+  $access = FALSE;
+  // If no composite node given, check if user has the abstract composite
+  // permission.
+  if (user_access('edit composite layouts')) {
+    $access = TRUE;
+  }
+  // Display the message only once.
+  if (! $displayed && $access) {
+    drupal_set_message(t("Deleted node(s) have been detected on this layout. Please at least update it to remove void references."), 'error');
+    $displayed = TRUE;
+  }
+}
\ No newline at end of file
