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

Comparing ray/src/common/bsdf_t.c (file contents):
Revision 3.11 by greg, Thu Apr 28 17:46:25 2011 UTC vs.
Revision 3.12 by greg, Sun May 1 16:34:37 2011 UTC

# Line 61 | Line 61 | SDnewNode(int nd, int lg)
61          if (lg < 0) {
62                  st = (SDNode *)malloc(sizeof(SDNode) +
63                                  sizeof(st->u.t[0])*((1<<nd) - 1));
64 <                if (st != NULL)
65 <                        memset(st->u.t, 0, sizeof(st->u.t[0])<<nd);
66 <        } else
67 <                st = (SDNode *)malloc(sizeof(SDNode) +
68 <                                sizeof(st->u.v[0])*((1 << nd*lg) - 1));
69 <                
70 <        if (st == NULL) {
71 <                if (lg < 0)
64 >                if (st == NULL) {
65                          sprintf(SDerrorDetail,
66                                  "Cannot allocate %d branch BSDF tree", 1<<nd);
67 <                else
67 >                        return NULL;
68 >                }
69 >                memset(st->u.t, 0, sizeof(st->u.t[0])<<nd);
70 >        } else {
71 >                st = (SDNode *)malloc(sizeof(SDNode) +
72 >                                sizeof(st->u.v[0])*((1 << nd*lg) - 1));        
73 >                if (st == NULL) {
74                          sprintf(SDerrorDetail,
75                                  "Cannot allocate %d BSDF leaves", 1 << nd*lg);
76 <                return NULL;
76 >                        return NULL;
77 >                }
78          }
79          st->ndim = nd;
80          st->log2GR = lg;
# Line 85 | Line 85 | SDnewNode(int nd, int lg)
85   static void
86   SDfreeTre(SDNode *st)
87   {
88 <        int     i;
88 >        int     n;
89  
90          if (st == NULL)
91                  return;
92 <        for (i = (st->log2GR < 0) << st->ndim; i--; )
93 <                SDfreeTre(st->u.t[i]);
92 >        for (n = (st->log2GR < 0) << st->ndim; n--; )
93 >                SDfreeTre(st->u.t[n]);
94          free((void *)st);
95   }
96  
# Line 473 | Line 473 | build_scaffold(float val, const double *cmin, double c
473                  sp->wmax = wid;
474          if (sp->alen >= sp->nall) {     /* need more space? */
475                  struct outdir_s *ndarr;
476 <                sp->nall += 8192;
476 >                sp->nall += 1024;
477                  ndarr = (struct outdir_s *)realloc(sp->darr,
478                                          sizeof(struct outdir_s)*sp->nall);
479 <                if (ndarr == NULL)
479 >                if (ndarr == NULL) {
480 >                        sprintf(SDerrorDetail,
481 >                                "Cannot grow scaffold to %u entries", sp->nall);
482                          return -1;      /* abort build */
483 +                }
484                  sp->darr = ndarr;
485          }
486                                          /* find Hilbert entry index */
# Line 521 | Line 524 | make_cdist(const SDTre *sdt, const double *pos)
524          myScaffold.wmax = 0;
525          myScaffold.nic = sdt->st->ndim - 2;
526          myScaffold.alen = 0;
527 <        myScaffold.nall = 8192;
527 >        myScaffold.nall = 512;
528          myScaffold.darr = (struct outdir_s *)malloc(sizeof(struct outdir_s) *
529                                                          myScaffold.nall);
530          if (myScaffold.darr == NULL)
# Line 536 | Line 539 | make_cdist(const SDTre *sdt, const double *pos)
539          cd = (SDTreCDst *)malloc(sizeof(SDTreCDst) +
540                                  sizeof(cd->carr[0])*myScaffold.alen);
541          if (cd == NULL) {
542 +                sprintf(SDerrorDetail,
543 +                        "Cannot allocate %u entry cumulative distribution",
544 +                                myScaffold.alen);
545                  free(myScaffold.darr);
546                  return NULL;
547          }
# Line 717 | Line 723 | next_token(char **spp)
723          return **spp;
724   }
725  
726 < #define eat_token(spp,c)        (next_token(spp)==(c) ? *(*(spp))++ : 0)
726 > /* Advance pointer past matching token (or any token if c==0) */
727 > #define eat_token(spp,c)        (next_token(spp)==(c) ^ !(c) ? *(*(spp))++ : 0)
728  
729   /* Count words from this point in string to '}' */
730   static int

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines