--- dia-0.97/app/load_save.c	2009-04-17 09:25:23.000000000 +0100
+++ dia-0.97-2pass/app/load_save.c	2009-12-02 18:07:42.203041731 +0000
@@ -613,7 +613,8 @@
     find_node_named (doc->xmlRootNode->xmlChildrenNode, "layer");
 
   objects_hash = g_hash_table_new(g_str_hash, g_str_equal);
-
+  
+  /* 1st pass: read in all objects for each layer */
   while (layer_node != NULL) {
     gchar *name;
     char *visible;
@@ -639,11 +640,10 @@
         layer->visible = TRUE;
       xmlFree(visible);
     }
-    /* Read in all objects: */
     
+    /* Read in all objects: */
     list = read_objects(layer_node, objects_hash, filename, NULL, unknown_objects_hash);
     layer_add_objects (layer, list);
-    read_connections( list, layer_node, objects_hash);
 
     data_add_layer(data, layer);
 
@@ -656,6 +656,22 @@
 
     layer_node = layer_node->next;
   }
+  
+  layer_node =
+    find_node_named (doc->xmlRootNode->xmlChildrenNode, "layer");
+
+  /* 2nd pass - connections */
+  for (layer_node = 
+          find_node_named (doc->xmlRootNode->xmlChildrenNode, "layer");
+       layer_node != NULL;
+       layer_node = layer_node->next) {
+    
+    if (xmlIsBlankNode(layer_node))
+      continue;
+
+    list = read_objects(layer_node, objects_hash, filename, NULL, unknown_objects_hash);
+    read_connections (list, layer_node, objects_hash);
+  }
 
   if (!active_layer)
     data->active_layer = (Layer *) g_ptr_array_index(data->layers, 0);
