From 6f58df1602bc981858c874a55c73dab0e76258cc Mon Sep 17 00:00:00 2001 From: jdl Date: Mon, 26 Jan 2004 20:14:47 +0000 Subject: catch emtpy arrays in arbran_bang and arbran_pdfscale svn path=/trunk/externals/maxlib/; revision=1295 --- src/arbran.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'src/arbran.c') diff --git a/src/arbran.c b/src/arbran.c index b4e4b2c..cb39963 100644 --- a/src/arbran.c +++ b/src/arbran.c @@ -23,8 +23,8 @@ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */ - -#include "m_pd.h" + +#include "m_pd.h" #include #include #include @@ -33,11 +33,11 @@ #ifndef M_PI #define M_PI 3.1415927 #endif - + static char *version = "arbran v0.1b, generates a random variable that conforms to the\n" " piecewise probability density in two arrays\n" " written by Olaf Matthes "; - + /* -------------------------- rand_arbran ------------------------------ */ static t_class *rand_arbran_class; @@ -58,7 +58,14 @@ static void rand_arbran_pdfscale(t_rand_arbran *x) t_int k = 0; t_float *tx, *tp; t_int ix, ip; - if (!garray_getfloatarray(bx, &ix, &tx)) + + if(!bx || !bp) + { + post("arbran: no arrays: pdfscale!"); + return; + } + + if (!garray_getfloatarray(bx, &ix, &tx)) { post("arbran: couldn't read from array!"); return; @@ -87,11 +94,19 @@ static void rand_arbran_bang(t_rand_arbran *x) t_int k = 0; t_float *tx, *tp; t_int ix, ip; - if (!garray_getfloatarray(bx, &ix, &tx)) + + if(!bx || !bp) + { + post("arbran: no arrays: bang!"); + return; + } + + if (!garray_getfloatarray(bx, &ix, &tx)) { post("arbran: couldn't read from array!"); return; } + if (!garray_getfloatarray(bp, &ip, &tp)) { post("arbran: couldn't read from array!"); @@ -158,9 +173,10 @@ static void *rand_arbran_new(t_symbol *s1, t_symbol *s2) t_rand_arbran *x = (t_rand_arbran *)pd_new(rand_arbran_class); srand( (unsigned)time( NULL ) ); outlet_new(&x->x_obj, &s_float); - x->x_x = s1; - x->x_p = s2; - rand_arbran_set(x); + rand_arbran_setarrays(x, s1, s2); + /* x->x_x = s1; + x->x_p = s2; + rand_arbran_set(x); */ return (x); } -- cgit v1.2.1