engorge_crender_vec: stash crenderlen

Rather than checking to see if there is enough space
for the crender vec following a geometry change, stash
the previous allocation, and realloc() whenever it
changes (i.e. whenever we get a resize). This brings
the crender vec back down in size if the screen gets
smaller, and seems to eliminate the problem in #1302.
pull/1321/head
nick black 4 years ago
parent 76983d6ba7
commit 89a557278b
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -309,10 +309,11 @@ typedef struct ncpile {
ncplane* top; // topmost plane, never NULL ncplane* top; // topmost plane, never NULL
ncplane* bottom; // bottommost plane, never NULL ncplane* bottom; // bottommost plane, never NULL
ncplane* roots; // head of root plane list ncplane* roots; // head of root plane list
struct crender* crender; // array (rows * cols crender objects)
struct notcurses* nc; // notcurses context struct notcurses* nc; // notcurses context
struct ncpile *prev, *next; // circular list struct ncpile *prev, *next; // circular list
size_t crenderlen; // size of crender vector
int dimy, dimx; // rows and cols at time of render int dimy, dimx; // rows and cols at time of render
struct crender* crender; // array (rows * cols crender objects)
} ncpile; } ncpile;
// the standard pile can be reached through ->stdplane. // the standard pile can be reached through ->stdplane.

@ -1151,22 +1151,22 @@ int ncpile_rasterize(ncplane* n){
return 0; return 0;
} }
// ensure the crender vector of 'n' is sufficiently large for // ensure the crender vector of 'n' is properly sized for 'n'->dimy x 'n'->dimx,
// 'n'->dimy x 'n'->dimx, having previously been 'dimy'x'dimx', and initialize // and initialize the rvec afresh for a new render.
// the rvec afresh for a new render.
static int static int
engorge_crender_vector(ncpile* n, int dimy, int dimx){ engorge_crender_vector(ncpile* n){
const int crenderlen = n->dimy * n->dimx; // desired size if(n->dimy <= 0 || n->dimx <= 0){
if(crenderlen <= 0){
return -1; return -1;
} }
const size_t crenderlen = n->dimy * n->dimx; // desired size
//fprintf(stderr, "crlen: %d y: %d x:%d\n", crenderlen, dimy, dimx); //fprintf(stderr, "crlen: %d y: %d x:%d\n", crenderlen, dimy, dimx);
if(crenderlen > dimy * dimx){ if(crenderlen != n->crenderlen){
struct crender* tmp = realloc(n->crender, sizeof(*tmp) * crenderlen); struct crender* tmp = realloc(n->crender, sizeof(*tmp) * crenderlen);
if(tmp == NULL){ if(tmp == NULL){
return -1; return -1;
} }
n->crender = tmp; n->crender = tmp;
n->crenderlen = crenderlen;
} }
init_rvec(n->crender, crenderlen); init_rvec(n->crender, crenderlen);
return 0; return 0;
@ -1177,11 +1177,9 @@ int ncpile_render(ncplane* n){
clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC, &start);
notcurses* nc = ncplane_notcurses(n); notcurses* nc = ncplane_notcurses(n);
ncpile* pile = ncplane_pile(n); ncpile* pile = ncplane_pile(n);
const int olddimy = pile->dimy;
const int olddimx = pile->dimx;
// update our notion of screen geometry, and render against that // update our notion of screen geometry, and render against that
notcurses_resize_internal(n, NULL, NULL); notcurses_resize_internal(n, NULL, NULL);
if(engorge_crender_vector(pile, olddimy, olddimx)){ if(engorge_crender_vector(pile)){
return -1; return -1;
} }
// FIXME notcurses_stdplane() doesn't belong here // FIXME notcurses_stdplane() doesn't belong here

Loading…
Cancel
Save