From 2dde60c27ab1397b1d3dcb68d4103abba30a5893 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 28 Nov 2019 12:12:15 -0500 Subject: [PATCH] ncplane_destroy(): pull it out of the zbuffer #26 --- src/lib/notcurses.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index ef3548947..e5925f792 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -372,13 +372,23 @@ ncplane* notcurses_newplane(notcurses* nc, int rows, int cols, } int ncplane_destroy(notcurses* nc, ncplane* ncp){ - if(ncp){ - if(nc->stdscr == ncp){ - return -1; - } - // FIXME close it up + if(ncp == NULL){ + return 0; } - return 0; + if(nc->stdscr == ncp){ + return -1; + } + ncplane** above; + // pull it out of the list + for(above = &nc->top ; *above ; above = &(*above)->z){ + if(*above == ncp){ + *above = ncp->z; + free_plane(ncp); + return 0; + } + } + // couldn't find it in our stack. don't try to free this interloper. + return -1; } static int