--- ray/src/common/octree.c 1989/02/02 10:34:37 1.1 +++ ray/src/common/octree.c 1998/08/24 15:30:11 2.3 @@ -15,7 +15,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include "octree.h" OCTREE *octblock[MAXOBLK]; /* our octree */ -static OCTREE ofreelist = EMPTY; /* free octree nodes */ +static OCTREE ofreelist = EMPTY; /* freed octree nodes */ static OCTREE treetop = 0; /* next free node */ @@ -33,7 +33,7 @@ octalloc() /* allocate an octree */ errno = 0; if (octbi(freet) >= MAXOBLK) return(EMPTY); - if ((octblock[octbi(freet)] = (OCTREE *)malloc( + if ((octblock[octbi(freet)] = (OCTREE *)bmalloc( (unsigned)256*8*sizeof(OCTREE))) == NULL) return(EMPTY); } @@ -56,6 +56,21 @@ register OCTREE ot; } +octdone() /* free EVERYTHING */ +{ + register int i; + + for (i = 0; i < MAXOBLK; i++) { + if (octblock[i] == NULL) + break; + bfree((char *)octblock[i], (unsigned)256*8*sizeof(OCTREE)); + octblock[i] = NULL; + } + ofreelist = EMPTY; + treetop = 0; +} + + OCTREE combine(ot) /* recursively combine nodes */ register OCTREE ot; @@ -69,8 +84,10 @@ register OCTREE ot; for (i = 1; i < 8; i++) if ((octkid(ot, i) = combine(octkid(ot, i))) != ores) ores = ot; - if (!istree(ores)) /* all were identical leaves */ - octfree(ot); + if (!istree(ores)) { /* all were identical leaves */ + octkid(ot, 0) = ofreelist; + ofreelist = ot; + } return(ores); }