--- ray/src/common/bsdf.c 2011/02/19 23:42:09 2.17 +++ ray/src/common/bsdf.c 2011/04/17 17:45:13 2.21 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf.c,v 2.17 2011/02/19 23:42:09 greg Exp $"; +static const char RCSid[] = "$Id: bsdf.c,v 2.21 2011/04/17 17:45:13 greg Exp $"; #endif /* * bsdf.c @@ -45,10 +45,14 @@ int SDretainSet = SDretainNone; SDError SDreportEnglish(SDError ec, FILE *fp) { - if (fp == NULL) - return ec; if (!ec) return SDEnone; + if ((ec < SDEnone) | (ec > SDEunknown)) { + SDerrorDetail[0] = '\0'; + ec = SDEunknown; + } + if (fp == NULL) + return ec; fputs(SDerrorEnglish[ec], fp); if (SDerrorDetail[0]) { fputs(": ", fp); @@ -269,10 +273,14 @@ SDclipName(char *res, const char *fname) /* Initialize an unused BSDF struct (simply clears to zeroes) */ void -SDclearBSDF(SDData *sd) +SDclearBSDF(SDData *sd, const char *fname) { - if (sd != NULL) - memset(sd, 0, sizeof(SDData)); + if (sd == NULL) + return; + memset(sd, 0, sizeof(SDData)); + if (fname == NULL) + return; + SDclipName(sd->name, fname); } /* Free data associated with BSDF struct */ @@ -330,7 +338,7 @@ SDgetCache(const char *bname) sdl->next = SDcacheList; SDcacheList = sdl; - sdl->refcnt++; + sdl->refcnt = 1; return &sdl->bsdf; } @@ -374,7 +382,7 @@ SDfreeCache(const SDData *sd) for (sdl = SDcacheList; sdl != NULL; sdl = (sdLast=sdl)->next) if (&sdl->bsdf == sd) break; - if (sdl == NULL || --sdl->refcnt) + if (sdl == NULL || (sdl->refcnt -= (sdl->refcnt > 0))) return; /* missing or still in use */ /* keep unreferenced data? */ if (SDisLoaded(sd) && SDretainSet) { @@ -451,7 +459,7 @@ SDmultiSamp(double t[], int n, double randX) bitmask_t ndx, coord[MS_MAXDIM]; while (n > MS_MAXDIM) /* punt for higher dimensions */ - t[--n] = drand48(); + t[--n] = rand()*(1./(RAND_MAX+.5)); nBits = (8*sizeof(bitmask_t) - 1) / n; ndx = randX * (double)((bitmask_t)1 << (nBits*n)); /* get coordinate on Hilbert curve */ @@ -459,7 +467,7 @@ SDmultiSamp(double t[], int n, double randX) /* convert back to [0,1) range */ scale = 1. / (double)((bitmask_t)1 << nBits); while (n--) - t[n] = scale * ((double)coord[n] + drand48()); + t[n] = scale * ((double)coord[n] + rand()*(1./(RAND_MAX+.5))); } #undef MS_MAXDIM