--- a/debian/patches/30-fix-undo.patch
+++ b/debian/patches/30-fix-undo.patch
@@ -0,0 +1,25 @@
+Description: Fix undo.
+             After undo-ing, the 'prev' pointer of the card that has been exposed
+             by the undo needs to be set to NULL.
+             The code to do this existed, but was being called before the undo.
+             This patch relocates this line of code to after the undo.
+Author: Graham Inggs <graham@nerve.org.za>
+Last-Update: 2013-06-23
+--- a/xsol.c
++++ b/xsol.c
+@@ -404,7 +404,6 @@
+    }                  
+    temp = piles[temp_undo->topile];
+    for(i=0; i<undo->numcards-1; i++) temp = temp->next;
+-   if(piles[temp_undo->topile] != NULL) piles[temp_undo->topile]->prev = NULL;
+    if(piles[temp_undo->frompile] != NULL) piles[temp_undo->frompile]->prev = temp;
+    piles[temp_undo->topile] = temp->next;
+    for(i=0; i<undo->numcards; i++) {
+@@ -420,6 +419,7 @@
+       if(temp_undo->frompile == 7) numcards++;
+       else if(temp_undo->topile == 7) numcards--;
+    }
++   if(piles[temp_undo->topile] != NULL) piles[temp_undo->topile]->prev = NULL;
+    if(temp_undo->score != 0) UpScore(temp_undo->score * -1);
+    undo = undo->next;
+    free(temp_undo);
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
 10-remove-alignment-option.patch
 20-fix-paint-glitches.patch
+30-fix-undo.patch
