]> git.neil.brown.name Git - edlib.git/commitdiff
tile: be extra careful when merging a tile into it's parent.
authorNeilBrown <neil@brown.name>
Fri, 16 Jun 2023 11:19:15 +0000 (21:19 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:41 +0000 (17:51 +1000)
When a parent tile gets down to just one child, the child is subsumed
into the parent.
This requires that the parent really is a tile pane.  As pane_reparent()
and change parantage, it is possible that it isn't.
So add extra checks before assuming the types of things.

Signed-off-by: NeilBrown <neil@brown.name>
lib-tile.c

index 5c75649407915dc20ac78a7fd94a566bea9ae8d4..90bb1dd68270889295aaf3c4fb59c6587cee42ae 100644 (file)
@@ -273,16 +273,11 @@ static int tile_destroy(struct pane *p safe)
        int pos, prevpos, nextpos;
        int remaining = 0;
 
-       if (ti->direction == Neither) {
-               /* Children have already been destroyed, just clean up */
-               free(ti->name); ti->name = NULL;
+       if (ti->direction == Neither /* Root file a tile-set */
+           || p->parent == p /* subsumbed hust being destroyed */
+           || p->parent->handle != p->handle /* Some messed with parentage */
+       )
                return 1;
-       }
-
-       if (p->parent == p) {
-               /* subsumed husk being destroyed */
-               return 1;
-       }
 
        if (ti->direction == Vert)
                pos = p->y;
@@ -306,7 +301,7 @@ static int tile_destroy(struct pane *p safe)
                remain = t;
        }
        /* There is always a sibling of a non-root */
-       ASSERT(remaining > 0);
+       //ASSERT(remaining > 0);
        if (prev == NULL /* FIXME redundant */ && next) {
                /* next gets the space and focus*/
                if (ti->direction == Horiz)
@@ -362,7 +357,8 @@ static int tile_destroy(struct pane *p safe)
                tile_adjust(prev);
        }
        list_del(&ti->tiles);
-       if (remaining == 1 && remain->parent != remain) {
+       if (remaining == 1 && remain && remain->parent != remain &&
+           remain->handle == p->handle) {
                struct tileinfo *ti2;
                enum dir tmp;
                /* Only one child left, must move it into parent.