ncplot: destroy ncplane on all paths #627

pull/1016/head
nick black 4 years ago
parent dca9db9687
commit 14cd8311e3
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -27,18 +27,22 @@ class ncppplot {
// if miny == maxy (enabling domain detection), they both must be equal to 0 // if miny == maxy (enabling domain detection), they both must be equal to 0
if(miny == maxy && miny){ if(miny == maxy && miny){
//logerror(nc, "Supplied non-zero domain detection param %d\n", miny); //logerror(nc, "Supplied non-zero domain detection param %d\n", miny);
ncplane_destroy(n);
return false; return false;
} }
if(opts->rangex < 0){ if(opts->rangex < 0){
//logerror(nc, "Supplied negative independent range %d\n", opts->rangex); //logerror(nc, "Supplied negative independent range %d\n", opts->rangex);
ncplane_destroy(n);
return false; return false;
} }
if(maxy < miny){ if(maxy < miny){
ncplane_destroy(n);
return false; return false;
} }
// DETECTMAXONLY can't be used without domain detection // DETECTMAXONLY can't be used without domain detection
if(opts->flags & NCPLOT_OPTION_DETECTMAXONLY && (miny != maxy)){ if(opts->flags & NCPLOT_OPTION_DETECTMAXONLY && (miny != maxy)){
//logerror(nc, "Supplied DETECTMAXONLY without domain detection"); //logerror(nc, "Supplied DETECTMAXONLY without domain detection");
ncplane_destroy(n);
return false; return false;
} }
ncblitter_e blitter = opts ? opts->gridtype : NCBLIT_DEFAULT; ncblitter_e blitter = opts ? opts->gridtype : NCBLIT_DEFAULT;
@ -53,11 +57,13 @@ class ncppplot {
auto bset = lookup_blitset(notcurses_canutf8(ncplane_notcurses(n)), auto bset = lookup_blitset(notcurses_canutf8(ncplane_notcurses(n)),
blitter, degrade_blitter); blitter, degrade_blitter);
if(bset == nullptr){ if(bset == nullptr){
ncplane_destroy(n);
return false; return false;
} }
int sdimy, sdimx; int sdimy, sdimx;
ncplane_dim_yx(n, &sdimy, &sdimx); ncplane_dim_yx(n, &sdimy, &sdimx);
if(sdimx <= 0){ if(sdimx <= 0){
ncplane_destroy(n);
return false; return false;
} }
int dimx = sdimx; int dimx = sdimx;
@ -85,31 +91,33 @@ class ncppplot {
} }
size_t slotsize = sizeof(*ncpp->slots) * ncpp->slotcount; size_t slotsize = sizeof(*ncpp->slots) * ncpp->slotcount;
ncpp->slots = static_cast<T*>(malloc(slotsize)); ncpp->slots = static_cast<T*>(malloc(slotsize));
if(ncpp->slots){ if(ncpp->slots == nullptr){
memset(ncpp->slots, 0, slotsize); ncplane_destroy(n);
ncpp->ncp = n; return false;
ncpp->maxchannels = opts->maxchannels; }
ncpp->minchannels = opts->minchannels; memset(ncpp->slots, 0, slotsize);
ncpp->bset = bset; ncpp->ncp = n;
ncpp->miny = miny; ncpp->maxchannels = opts->maxchannels;
ncpp->maxy = maxy; ncpp->minchannels = opts->minchannels;
ncpp->vertical_indep = opts->flags & NCPLOT_OPTION_VERTICALI; ncpp->bset = bset;
ncpp->exponentiali = opts->flags & NCPLOT_OPTION_EXPONENTIALD; ncpp->miny = miny;
ncpp->detectonlymax = opts->flags & NCPLOT_OPTION_DETECTMAXONLY; ncpp->maxy = maxy;
if( (ncpp->detectdomain = (miny == maxy)) ){ ncpp->vertical_indep = opts->flags & NCPLOT_OPTION_VERTICALI;
ncpp->maxy = 0; ncpp->exponentiali = opts->flags & NCPLOT_OPTION_EXPONENTIALD;
ncpp->miny = std::numeric_limits<T>::max(); ncpp->detectonlymax = opts->flags & NCPLOT_OPTION_DETECTMAXONLY;
} if( (ncpp->detectdomain = (miny == maxy)) ){
ncpp->slotstart = 0; ncpp->maxy = 0;
ncpp->slotx = 0; ncpp->miny = std::numeric_limits<T>::max();
ncpp->redraw_plot();
return true;
} }
return false; ncpp->slotstart = 0;
ncpp->slotx = 0;
ncpp->redraw_plot();
return true;
} }
void destroy(){ void destroy(){
free(slots); free(slots);
ncplane_destroy(ncp);
} }
auto redraw_plot() -> int { auto redraw_plot() -> int {

Loading…
Cancel
Save