--- ray/src/hd/rholo3.c 1997/11/03 18:33:13 3.2 +++ ray/src/hd/rholo3.c 1997/11/04 11:52:21 3.4 @@ -15,10 +15,10 @@ static char SCCSid[] = "$SunId$ SGI"; #define sgn(x) ((x) > 0 ? 1 : (x) < 0 ? -1 : 0) -static PACKHEAD *complist; /* list of beams to compute */ -static int complen; /* length of complist */ -static int listpos; /* current list position for next_packet */ -static int lastin = -1; /* last ordered position in list */ +static PACKHEAD *complist=NULL; /* list of beams to compute */ +static int complen=0; /* length of complist */ +static int listpos=0; /* current list position for next_packet */ +static int lastin= -1; /* last ordered position in list */ int @@ -110,8 +110,8 @@ int nents; lastin = -1; /* flag full sort */ break; } - /* sort updated list */ - sortcomplist(); + if (lastin < 0) /* sort updated list */ + sortcomplist(); return; /* no display */ default: error(CONSISTENCY, "bundle_set called with unknown operation"); @@ -121,10 +121,11 @@ int nents; if (clist[i].nr > n) n = clist[i].nr; p = (PACKHEAD *)malloc(sizeof(PACKHEAD) + n*sizeof(RAYVAL)); - /* now, display what we can */ + if (p == NULL) + goto memerr; + /* display what we have */ for (i = 0; i < nents; i++) - if (clist[i].nr > 0 && - (b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) { + if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) { bcopy((char *)hdbray(b), (char *)(p+1), (p->nr=b->nrm)*sizeof(RAYVAL)); disp_packet((PACKET *)p); @@ -204,6 +205,9 @@ init_global() /* initialize global ray computation * int lseg[2][3]; double frac; register int k; + /* free old list */ + if (complen > 0) + free((char *)complist); /* allocate beam list */ complen = 0; for (j = 0; hdlist[j] != NULL; j++) @@ -232,7 +236,7 @@ init_global() /* initialize global ray computation * while (k--) complist[k].nr = frac * complist[k].nr; } - listpos = 0; lastin = -1; + listpos = 0; lastin = -1; /* flag initial sort */ } @@ -266,7 +270,7 @@ sortcomplist() /* fix our list order */ /* empty queue */ done_packets(flush_queue()); - if (complen <= 0) /* check to see if there even is a list */ + if (complen <= 0) /* check to see if there is even a list */ return; if (lastin < 0) /* flag to sort entire list */ qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); @@ -290,7 +294,11 @@ sortcomplist() /* fix our list order */ for (i = complen; i-- && complist[i].nr <= bnrays(hdlist[complist[i].hd],complist[i].bi); ) ; - if (i < complen-1) { + if (i < 0) { + free((char *)complist); + complist = NULL; + complen = 0; + } else if (i < complen-1) { list2 = (PACKHEAD *)realloc((char *)complist, (i+1)*sizeof(PACKHEAD)); if (list2 != NULL) {