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

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.36 by greg, Wed Feb 14 15:43:22 1996 UTC vs.
Revision 2.37 by greg, Tue May 28 14:24:44 1996 UTC

# Line 121 | Line 121 | double  newa;
121   setambient(afile)                       /* initialize calculation */
122   char  *afile;
123   {
124 <        long  headlen;
124 >        long  pos, flen;
125          AMBVAL  amb;
126                                                  /* init ambient limits */
127          setambres(ambres);
# Line 137 | Line 137 | char  *afile;
137                                                  /* open ambient file */
138          if ((ambfp = fopen(afile, "r+")) != NULL) {
139                  initambfile(0);
140 <                headlen = ftell(ambfp);
140 >                pos = ftell(ambfp);
141                  while (readambval(&amb, ambfp))
142                          avinsert(avstore(&amb));
143                                                  /* align */
144 <                fseek(ambfp, -((ftell(ambfp)-headlen)%AMBVALSIZ), 1);
144 >                pos += (long)nambvals*AMBVALSIZ;
145 >                flen = lseek(fileno(ambfp), 0L, 2);
146 >                if (flen != pos) {
147 >                        error(WARNING,
148 >                        "ignoring last %ld values in ambient file (corrupted)",
149 >                                        (flen - pos)/AMBVALSIZ);
150 >                        fseek(ambfp, pos, 0);
151 >                        ftruncate(fileno(ambfp), pos);
152 >                }
153                  nambshare = nambvals;
154          } else if ((ambfp = fopen(afile, "w+")) != NULL)
155                  initambfile(1);
# Line 731 | Line 739 | ambsync()                      /* synchronize ambient file */
739                  if (fseek(ambinp, lastpos, 0) < 0)
740                          goto seekerr;
741                  while (n >= AMBVALSIZ) {        /* load contributed values */
742 <                        readambval(&avs, ambinp);
742 >                        if (!readambval(&avs, ambinp)) {
743 >                                sprintf(errmsg,
744 >                                "ambient file corrupted near character %ld",
745 >                                                flen - n);
746 >                                error(WARNING, errmsg);
747 >                                break;
748 >                        }
749                          avinsert(avstore(&avs));
750                          n -= AMBVALSIZ;
751                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines