Index: app/display/gimpdisplayshell-render.c
===================================================================
--- app/display/gimpdisplayshell-render.c	(revision 23441)
+++ app/display/gimpdisplayshell-render.c	(working copy)
@@ -1030,12 +1030,71 @@
  *  678
  */
 
+static gboolean sanity (Tile         **tile,
+                        gint           n_tiles,
+                        const guchar  *src[9],
+                        gint           line)
+{
+  gint src_no;
+
+
+  for (src_no = 0; src_no < 9; src_no++)
+    {
+      gint best_tile = -1;
+      gint best_distance = 128*128*4  *2; /* allow overshooting by quite a lot */
+      gint tile_no;
+      if (!src[src_no])
+        {
+          g_warning ("%i no src data for src[%i]", line, src_no);
+          return FALSE;
+        }
+      for (tile_no = 0; tile_no < n_tiles; tile_no++)
+        {
+          if (tile[tile_no])
+            {
+              const guchar *tile_base;
+              gint distance;
+              tile_base = tile_data_pointer (tile[tile_no], 0, 0);
+              distance = src[src_no]-tile_base;
+              if (distance < best_distance &&
+                  distance >= 0)
+                {
+                  best_tile = tile_no;
+                  best_distance = distance;
+                }
+            }
+        }
+      if (best_tile == -1)
+        {
+          g_warning ("%i: no matching tile data for src[%i](%p)", line, src_no, src[src_no]);
+          return FALSE;
+        }
+      else
+        {
+          if (best_distance >= tile_size (tile[best_tile]))
+            {
+              Tile *btile = tile[best_tile];
+              g_warning ("%i: src[%i] goes beyond the limits of tile[%i], which is a %ix%i tile, offest: %i overshoot: %ibytes, (badrequest:%i,%i)", line,
+               src_no, best_tile, tile_ewidth(btile), tile_eheight(btile),
+               best_distance, best_distance-tile_size(btile),
+               (best_distance/tile_bpp(btile)) % tile_ewidth(btile),
+               (best_distance/tile_bpp(btile)) / tile_ewidth(btile));
+              return FALSE;
+            }
+        }
+    }
+  return TRUE;
+};
+
+#define badSANITY  if(!sanity(tile, 9, src, __LINE__)){g_on_error_stack_trace("gimp");}
+#define SANITY  if(!sanity(tile, 9, src, __LINE__))g_warning("x:%i,y:%i (%i,%i)", (gint) (x>>16), info->src_y,  (gint)(x>>16)%TILE_WIDTH, (gint)info->src_y % TILE_HEIGHT);
+
 /* function to render a horizontal line of view data */
 static const guchar *
 render_image_tile_fault (RenderInfo *info)
 {
-  Tile         *tile[9];
-  const guchar *src[9];
+  Tile         *tile[9]={NULL,};
+  const guchar *src[9]={NULL,};
 
   guchar       *dest;
   gint          width;
@@ -1242,6 +1301,7 @@
       src[6] = src[7];  /* reusing existing pixel data */
     }
 
+
   bpp    = tile_manager_bpp (info->src_tiles);
   dest   = tile_buf;
 
@@ -1255,6 +1315,7 @@
 
   xdelta = info->xdelta;
 
+  SANITY
   do
     {
       gint  src_x = x >> 16;
@@ -1274,6 +1335,7 @@
 
         center_weight = footprint_x - left_weight - right_weight;
 
+      SANITY
       box_filter (left_weight, center_weight, right_weight,
                   top_weight, middle_weight, bottom_weight, foosum,
                   src, dest, bpp);
@@ -1394,13 +1456,6 @@
               tile[5] = tile_manager_get_tile (info->src_tiles,
                                                src_x + 1, info->src_y,
                                                TRUE, FALSE);
-              tile[8] = tile_manager_get_tile (info->src_tiles,
-                                               src_x + 1, info->src_y + 1,
-                                               TRUE, FALSE);
-              tile[2] = tile_manager_get_tile (info->src_tiles,
-                                               src_x + 1, info->src_y - 1,
-                                               TRUE, FALSE);
-
               if (!tile[5])
                 {
                   src[5] = src[4];
@@ -1412,6 +1467,9 @@
                                               info->src_y % TILE_HEIGHT);
                 }
 
+              tile[8] = tile_manager_get_tile (info->src_tiles,
+                                               src_x + 1, info->src_y + 1,
+                                               TRUE, FALSE);
               if (!tile[8])
                 {
                   src[8] = src[7];
@@ -1423,6 +1481,9 @@
                                               (info->src_y + 1) % TILE_HEIGHT);
                 }
 
+              tile[2] = tile_manager_get_tile (info->src_tiles,
+                                               src_x + 1, info->src_y - 1,
+                                               TRUE, FALSE);
               if (!tile[2])
                 {
                   src[2] = src[1];
@@ -1582,6 +1643,10 @@
   return tile_buf;
 }
 
+#undef SANITY
+#define SANITY  if(!sanity(tile, 3, src, __LINE__))g_warning("x:%i,y:%i (%i,%i)", (gint) (x>>16), info->src_y,  (gint)(x>>16)%TILE_WIDTH, (gint)info->src_y % TILE_HEIGHT);
+
+
 static const guchar *
 render_image_tile_fault_one_row (RenderInfo *info)
 {
@@ -1655,30 +1720,27 @@
   src[7] = tile_data_pointer (tile[0],
                               info->src_x % TILE_WIDTH,
                               (info->src_y + 1) % TILE_HEIGHT);
+  src[1] = tile_data_pointer (tile[0],
+                              (info->src_x) % TILE_WIDTH,
+                              (info->src_y - 1) % TILE_HEIGHT);
+
   if (tile[1])
     {
       src[5] = tile_data_pointer (tile[1],
-                                  (info->src_x + 1)% TILE_WIDTH,
-                                  info->src_y % TILE_HEIGHT);
+                                  (info->src_x + 1) % TILE_WIDTH,
+                                  (info->src_y    ) % TILE_HEIGHT);
       src[8] = tile_data_pointer (tile[1],
                                   (info->src_x + 1) % TILE_WIDTH,
                                   (info->src_y + 1) % TILE_HEIGHT);
-    }
-  else
-    {
-      src[5] = src[4];  /* reusing existing pixel data */
-      src[8] = src[5];  /* reusing existing pixel data */
-    }
-
-  if (tile[0])
-    {
-      src[1] = tile_data_pointer (tile[0],
-                                  (info->src_x) % TILE_WIDTH,
+      src[2] = tile_data_pointer (tile[1],
+                                  (info->src_x + 1) % TILE_WIDTH,
                                   (info->src_y - 1) % TILE_HEIGHT);
     }
   else
     {
-      src[1] = src[4];  /* reusing existing pixel data */
+      src[5] = src[4];
+      src[8] = src[4]; 
+      src[2] = src[4];  
     }
 
   if (tile[2])
@@ -1686,25 +1748,6 @@
       src[0] = tile_data_pointer (tile[2],
                                   (info->src_x - 1) % TILE_WIDTH,
                                   (info->src_y - 1) % TILE_HEIGHT);
-    }
-  else
-    {
-      src[0] = src[1];  /* reusing existing pixel data */
-    }
-
-  if (tile[1])
-    {
-      src[2] = tile_data_pointer (tile[1],
-                                  (info->src_x + 1) % TILE_WIDTH,
-                                  (info->src_y - 1) % TILE_HEIGHT);
-    }
-  else
-    {
-      src[2] = src[4];  /* reusing existing pixel data */
-    }
-
-  if (tile[2])
-    {
       src[3] = tile_data_pointer (tile[2],
                                   (info->src_x - 1) % TILE_WIDTH,
                                   (info->src_y) % TILE_HEIGHT);
@@ -1714,6 +1757,7 @@
     }
   else
     {
+      src[0] = src[1];  /* reusing existing pixel data */
       src[3] = src[4];  /* reusing existing pixel data */
       src[6] = src[7];  /* reusing existing pixel data */
     }
@@ -1730,7 +1774,7 @@
   tilexL = (info->src_x - 1) / TILE_WIDTH;
 
   xdelta = info->xdelta;
-
+  SANITY
   do
     {
       gint  src_x = x >> 16;
@@ -1750,6 +1794,7 @@
 
         center_weight = footprint_x - left_weight - right_weight;
 
+        SANITY
         box_filter (left_weight, center_weight, right_weight,
                     top_weight, middle_weight, bottom_weight, foosum,
                     src, dest, bpp);
@@ -1849,14 +1894,22 @@
                 }
               else
                 {
+                  if (tile_ewidth (tile[1]) != TILE_WIDTH)
+                    {
+                      gint ewidth = tile_ewidth (tile[1]);
+                      gint localx = (src_x+1) % TILE_WIDTH;
+                      if (localx>=ewidth)
+                        g_warning ("effective width: %i, want to use: %i",
+                                   ewidth, localx);
+                    }
                   src[5] = tile_data_pointer (tile[1],
-                                              (src_x + 1) % TILE_WIDTH,
-                                              info->src_y % TILE_HEIGHT);
+                                              (src_x + 1  ) % TILE_WIDTH,
+                                              (info->src_y) % TILE_HEIGHT);
                   src[8] = tile_data_pointer (tile[1],
-                                              (src_x + 1) % TILE_WIDTH,
+                                              (src_x + 1      ) % TILE_WIDTH,
                                               (info->src_y + 1) % TILE_HEIGHT);
                   src[2] = tile_data_pointer (tile[1],
-                                              (src_x + 1) % TILE_WIDTH,
+                                              (src_x + 1      ) % TILE_WIDTH,
                                               (info->src_y - 1) % TILE_HEIGHT);
                 }
             }
@@ -1882,7 +1935,7 @@
                 {
                   src[3] = tile_data_pointer (tile[2],
                                               (src_x - 1) % TILE_WIDTH,
-                                              info->src_y % TILE_HEIGHT);
+                                              (info->src_y) % TILE_HEIGHT);
                   src[6] = tile_data_pointer (tile[2],
                                               (src_x - 1) % TILE_WIDTH,
                                               (info->src_y + 1) % TILE_HEIGHT);
