ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/bsdf.c
(Generate patch)

Comparing ray/src/common/bsdf.c (file contents):
Revision 2.18 by greg, Fri Apr 8 23:23:28 2011 UTC vs.
Revision 2.21 by greg, Sun Apr 17 17:45:13 2011 UTC

# Line 45 | Line 45 | int                    SDretainSet = SDretainNone;
45   SDError
46   SDreportEnglish(SDError ec, FILE *fp)
47   {
48        if (fp == NULL)
49                return ec;
48          if (!ec)
49                  return SDEnone;
50 +        if ((ec < SDEnone) | (ec > SDEunknown)) {
51 +                SDerrorDetail[0] = '\0';
52 +                ec = SDEunknown;
53 +        }
54 +        if (fp == NULL)
55 +                return ec;
56          fputs(SDerrorEnglish[ec], fp);
57          if (SDerrorDetail[0]) {
58                  fputs(": ", fp);
# Line 269 | Line 273 | SDclipName(char *res, const char *fname)
273  
274   /* Initialize an unused BSDF struct (simply clears to zeroes) */
275   void
276 < SDclearBSDF(SDData *sd)
276 > SDclearBSDF(SDData *sd, const char *fname)
277   {
278 <        if (sd != NULL)
279 <                memset(sd, 0, sizeof(SDData));
278 >        if (sd == NULL)
279 >                return;
280 >        memset(sd, 0, sizeof(SDData));
281 >        if (fname == NULL)
282 >                return;
283 >        SDclipName(sd->name, fname);
284   }
285  
286   /* Free data associated with BSDF struct */
# Line 330 | Line 338 | SDgetCache(const char *bname)
338          sdl->next = SDcacheList;
339          SDcacheList = sdl;
340  
341 <        sdl->refcnt++;
341 >        sdl->refcnt = 1;
342          return &sdl->bsdf;
343   }
344  
# Line 374 | Line 382 | SDfreeCache(const SDData *sd)
382          for (sdl = SDcacheList; sdl != NULL; sdl = (sdLast=sdl)->next)
383                  if (&sdl->bsdf == sd)
384                          break;
385 <        if (sdl == NULL || --sdl->refcnt)
385 >        if (sdl == NULL || (sdl->refcnt -= (sdl->refcnt > 0)))
386                  return;                 /* missing or still in use */
387                                          /* keep unreferenced data? */
388          if (SDisLoaded(sd) && SDretainSet) {
# Line 451 | Line 459 | SDmultiSamp(double t[], int n, double randX)
459          bitmask_t       ndx, coord[MS_MAXDIM];
460          
461          while (n > MS_MAXDIM)           /* punt for higher dimensions */
462 <                t[--n] = rand()*(1./RAND_MAX);
462 >                t[--n] = rand()*(1./(RAND_MAX+.5));
463          nBits = (8*sizeof(bitmask_t) - 1) / n;
464          ndx = randX * (double)((bitmask_t)1 << (nBits*n));
465                                          /* get coordinate on Hilbert curve */
# Line 459 | Line 467 | SDmultiSamp(double t[], int n, double randX)
467                                          /* convert back to [0,1) range */
468          scale = 1. / (double)((bitmask_t)1 << nBits);
469          while (n--)
470 <                t[n] = scale * ((double)coord[n] + rand()*(1./RAND_MAX));
470 >                t[n] = scale * ((double)coord[n] + rand()*(1./(RAND_MAX+.5)));
471   }
472  
473   #undef MS_MAXDIM

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines