--- ray/src/rt/source.c 1991/10/21 14:23:36 1.46 +++ ray/src/rt/source.c 1992/01/09 09:53:00 2.2 @@ -100,10 +100,10 @@ marksources() /* find and mark source objects */ } markvirtuals(); /* find and add virtual sources */ /* allocate our contribution arrays */ - maxcntr = nsources + MAXSPART*2; /* start with this many */ + maxcntr = nsources + MAXSPART; /* start with this many */ srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB)); cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR)); - if (srccnt == NULL || cntord == NULL) + if (srccnt == NULL | cntord == NULL) goto memerr; return; memerr: @@ -123,7 +123,7 @@ SRCINDEX *si; /* source sample index */ rayorigin(sr, r, SHADOW, 1.0); /* ignore limits */ - while ((d = nextssamp(sr->rorg, sr->rdir, si)) != 0.0) { + while ((d = nextssamp(sr, si)) != 0.0) { sr->rsrc = si->sn; /* remember source */ srcp = source + si->sn; if (srcp->sflags & SDISTANT) { @@ -228,7 +228,7 @@ char *p; /* data for f */ maxcntr*sizeof(CONTRIB)); cntord = (CNTPTR *)realloc((char *)cntord, maxcntr*sizeof(CNTPTR)); - if (srccnt == NULL || cntord == NULL) + if (srccnt == NULL | cntord == NULL) error(SYSTEM, "out of memory in direct"); } cntord[sn].sndx = sn; @@ -261,6 +261,8 @@ char *p; /* data for f */ l = m; } } + if (ncnts == 0) + return; /* no contributions! */ /* accumulate tail */ for (sn = ncnts-1; sn > 0; sn--) cntord[sn-1].brt += cntord[sn].brt;