From 9c1e713914d5c10c0a2606125226b0ded5997cd3 Mon Sep 17 00:00:00 2001 From: Nick Lanham Date: Tue, 7 Feb 2012 12:22:26 +0100 Subject: [PATCH] Fix some segfaults for kits with invalid instrument entries. Also fix a couple in internal segfaults. --- drmr.c | 16 +++++++++++++--- drmr_hydrogen.c | 8 +++++--- drmr_hydrogen.h | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drmr.c b/drmr.c index 006f446..9c787a1 100644 --- a/drmr.c +++ b/drmr.c @@ -35,7 +35,7 @@ int load_sample(char* path, drmr_sample* samp) { sndf = sf_open(path,SFM_READ,&(samp->info)); if (!sndf) { - fprintf(stderr,"Failed to open sound file: %s\n",sf_strerror(sndf)); + fprintf(stderr,"Failed to open sound file: %s - %s\n",path,sf_strerror(sndf)); return 1; } @@ -63,7 +63,12 @@ static void* load_thread(void* arg) { for(;;) { pthread_cond_wait(&drmr->load_cond, &drmr->load_mutex); - load_hydrogen_kit(drmr,drmr->kits->kits[drmr->curKit].path); + if (drmr->curKit >= drmr->kits->num_kits) { + int os = drmr->num_samples; + drmr->num_samples = 0; + if (os > 0) free_samples(drmr->samples,os); + } else + load_hydrogen_kit(drmr,drmr->kits->kits[drmr->curKit].path); } pthread_mutex_unlock(&drmr->load_mutex); return 0; @@ -118,6 +123,7 @@ instantiate(const LV2_Descriptor* descriptor, free(drmr); return 0; } + drmr->samples = NULL; // prevent attempted freeing in load load_hydrogen_kit(drmr,drmr->kits->kits->path); drmr->curKit = 0; @@ -247,7 +253,11 @@ static void run(LV2_Handle instance, uint32_t n_samples) { int pos,lim; drmr_sample* cs = drmr->samples+i; if (cs->active) { - float gain = *(drmr->gains[i]); + float gain; + if (i < 16) + gain = *(drmr->gains[i]); + else + gain = 1.0f; one_active = 1; if (cs->info.channels == 1) { // play mono sample lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset)); diff --git a/drmr_hydrogen.c b/drmr_hydrogen.c index 1501c0d..eb5385b 100644 --- a/drmr_hydrogen.c +++ b/drmr_hydrogen.c @@ -112,8 +112,10 @@ endElement(void *userData, const char *name) info->cur_off = 0; - if (!info->scan_only && info->in_instrument && !strcmp(name,"instrument")) { - // ending an instrument, add current struct to end of list + if (!info->scan_only && + info->in_instrument && + !strcmp(name,"instrument") && + info->cur_instrument->filename) { struct instrument_info * cur_i = info->kit_info->instruments; if (cur_i) { while(cur_i->next) cur_i = cur_i->next; @@ -249,7 +251,7 @@ kits* scan_kits() { return ret; } -static void free_samples(drmr_sample* samples, int num_samples) { +void free_samples(drmr_sample* samples, int num_samples) { int i; for (i=0;i