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.72 by greg, Fri Apr 11 22:54:34 2014 UTC vs.
Revision 2.101 by schorsch, Sun Mar 6 01:13:17 2016 UTC

# Line 1 | Line 1
1 #ifndef lint
1   static const char       RCSid[] = "$Id$";
3 #endif
2   /*
3   *  ambient.c - routines dealing with ambient (inter-reflected) component.
4   *
# Line 17 | Line 15 | static const char      RCSid[] = "$Id$";
15   #include  "resolu.h"
16   #include  "ambient.h"
17   #include  "random.h"
18 + #include  "pmapamb.h"
19  
20   #ifndef  OCTSCALE
21   #define  OCTSCALE       1.0     /* ceil((valid rad.)/(cube size)) */
# Line 51 | Line 50 | static int  nunflshed = 0;     /* number of unflushed ambi
50   #define MAX_SORT_INTVL  (SORT_INTVL<<6)
51   #endif
52  
53 +
54   static double  avsum = 0.;              /* computed ambient value sum (log) */
55   static unsigned int  navsum = 0;        /* number of values in avsum */
56   static unsigned int  nambvals = 0;      /* total number of indirect values */
# Line 108 | Line 108 | setambres(                             /* set ambient resolution */
108                                                  /* set min & max radii */
109          if (ar <= 0) {
110                  minarad = 0;
111 <                maxarad = thescene.cusize / 2.0;
111 >                maxarad = thescene.cusize*0.2;
112          } else {
113                  minarad = thescene.cusize / ar;
114 <                maxarad = 64 * minarad;                 /* heuristic */
115 <                if (maxarad > thescene.cusize / 2.0)
116 <                        maxarad = thescene.cusize / 2.0;
114 >                maxarad = 64.0 * minarad;               /* heuristic */
115 >                if (maxarad > thescene.cusize*0.2)
116 >                        maxarad = thescene.cusize*0.2;
117          }
118          if (minarad <= FTINY)
119 <                minarad = 10*FTINY;
119 >                minarad = 10.0*FTINY;
120          if (maxarad <= minarad)
121 <                maxarad = 64 * minarad;
121 >                maxarad = 64.0 * minarad;
122   }
123  
124  
# Line 127 | Line 127 | setambacc(                             /* set ambient accuracy */
127          double  newa
128   )
129   {
130 <        double  ambdiff;
131 <
132 <        if (newa < 0.0)
133 <                newa = 0.0;
134 <        ambdiff = fabs(newa - ambacc);
135 <        if (ambdiff >= .01 && (ambacc = newa) > FTINY && nambvals > 0)
136 <                sortambvals(1);                 /* rebuild tree */
130 >        static double   olda;           /* remember previous setting here */
131 >        
132 >        newa *= (newa > 0);
133 >        if (fabs(newa - olda) >= .05*(newa + olda)) {
134 >                ambacc = newa;
135 >                if (nambvals > 0)
136 >                        sortambvals(1);         /* rebuild tree */
137 >        }
138   }
139  
140  
# Line 163 | Line 164 | setambient(void)                               /* initialize calculation */
164                  initambfile(0);                 /* file exists */
165                  lastpos = ftell(ambfp);
166                  while (readambval(&amb, ambfp))
167 <                        avinsert(avstore(&amb));
167 >                        avstore(&amb);
168                  nambshare = nambvals;           /* share loaded values */
169                  if (readonly) {
170                          sprintf(errmsg,
# Line 183 | Line 184 | setambient(void)                               /* initialize calculation */
184                                          (flen - lastpos)/AMBVALSIZ);
185                          error(WARNING, errmsg);
186                          fseek(ambfp, lastpos, SEEK_SET);
186 #ifndef _WIN32 /* XXX we need a replacement for that one */
187                          ftruncate(fileno(ambfp), (off_t)lastpos);
188 #endif
188                  }
189          } else if ((ambfp = fopen(ambfile, "w+")) != NULL) {
190                  initambfile(1);                 /* else create new file */
# Line 195 | Line 194 | setambient(void)                               /* initialize calculation */
194                  sprintf(errmsg, "cannot open ambient file \"%s\"", ambfile);
195                  error(SYSTEM, errmsg);
196          }
198 #ifdef getc_unlocked
199        flockfile(ambfp);                       /* application-level lock */
200 #endif
197   #ifdef  F_SETLKW
198          aflock(F_UNLCK);                        /* release file */
199   #endif
# Line 218 | Line 214 | ambdone(void)                  /* close ambient file and free memory
214                  lastpos = -1;
215          }
216                                          /* free ambient tree */
217 <        unloadatree(&atrunk, &avfree);
217 >        unloadatree(&atrunk, avfree);
218                                          /* reset state variables */
219          avsum = 0.;
220          navsum = 0;
# Line 261 | Line 257 | ambnotify(                     /* record new modifier */
257  
258   /************ THE FOLLOWING ROUTINES DIFFER BETWEEN NEW & OLD ***************/
259  
260 < #ifdef NEWAMB
260 > #ifndef OLDAMB
261  
262   #define tfunc(lwr, x, upr)      (((x)-(lwr))/((upr)-(lwr)))
263  
264 + static int      plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang);
265   static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
266                                  AMBTREE *at, FVECT c0, double s);
267   static int      makeambient(COLOR acol, RAY *r, FVECT rn, int al);
268 < static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
268 > static int      extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
269                                  FVECT uvw[3]);
270  
271   void
# Line 279 | Line 276 | multambient(           /* compute ambient component & multiply
276   )
277   {
278          static int  rdepth = 0;                 /* ambient recursion */
279 <        COLOR   acol;
279 >        COLOR   acol, caustic;
280          int     ok;
281          double  d, l;
282  
283 +        /* PMAP: Factor in ambient from photon map, if enabled and ray is
284 +         * ambient. Return as all ambient components accounted for, else
285 +         * continue. */
286 +        if (ambPmap(aval, r, rdepth))
287 +                return;
288 +
289 +        /* PMAP: Factor in specular-diffuse ambient (caustics) from photon
290 +         * map, if enabled and ray is primary, else caustic is zero.  Continue
291 +         * with RADIANCE ambient calculation */
292 +        copycolor(caustic, aval);
293 +        ambPmapCaustic(caustic, r, rdepth);
294 +        
295          if (ambdiv <= 0)                        /* no ambient calculation */
296                  goto dumbamb;
297                                                  /* check number of bounces */
# Line 296 | Line 305 | multambient(           /* compute ambient component & multiply
305          if (ambacc <= FTINY) {                  /* no ambient storage */
306                  copycolor(acol, aval);
307                  rdepth++;
308 <                ok = doambient(acol, r, r->rweight, NULL, NULL, NULL, NULL);
308 >                ok = doambient(acol, r, r->rweight,
309 >                                NULL, NULL, NULL, NULL, NULL);
310                  rdepth--;
311                  if (!ok)
312                          goto dumbamb;
313                  copycolor(aval, acol);
314 +
315 +                /* PMAP: add in caustic */
316 +                addcolor(aval, caustic);
317                  return;
318          }
319  
# Line 310 | Line 323 | multambient(           /* compute ambient component & multiply
323          setcolor(acol, 0.0, 0.0, 0.0);
324          d = sumambient(acol, r, nrm, rdepth,
325                          &atrunk, thescene.cuorg, thescene.cusize);
326 +                        
327          if (d > FTINY) {
328                  d = 1.0/d;
329                  scalecolor(acol, d);
330                  multcolor(aval, acol);
331 +
332 +                /* PMAP: add in caustic */
333 +                addcolor(aval, caustic);
334                  return;
335          }
336 +        
337          rdepth++;                               /* need to cache new value */
338          ok = makeambient(acol, r, nrm, rdepth-1);
339          rdepth--;
340 +        
341          if (ok) {
342 <                multcolor(aval, acol);          /* got new value */
342 >                multcolor(aval, acol);          /* computed new value */
343 >
344 >                /* PMAP: add in caustic */
345 >                addcolor(aval, caustic);
346                  return;
347          }
348 +        
349   dumbamb:                                        /* return global value */
350          if ((ambvwt <= 0) | (navsum == 0)) {
351                  multcolor(aval, ambval);
352 +                
353 +                /* PMAP: add in caustic */
354 +                addcolor(aval, caustic);
355                  return;
356          }
357 <        l = bright(ambval);                     /* average in computations */
357 >        
358 >        l = bright(ambval);                     /* average in computations */  
359          if (l > FTINY) {
360                  d = (log(l)*(double)ambvwt + avsum) /
361                                  (double)(ambvwt + navsum);
# Line 342 | Line 369 | dumbamb:                                       /* return global value */
369   }
370  
371  
372 < double
372 > /* Plug a potential leak where ambient cache value is occluded */
373 > static int
374 > plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang)
375 > {
376 >        const double    cost70sq = 0.1169778;   /* cos(70deg)^2 */
377 >        RAY             rtst;
378 >        FVECT           vdif;
379 >        double          normdot, ndotd, nadotd;
380 >        double          a, b, c, t[2];
381 >
382 >        ang += 2.*PI*(ang < 0);                 /* check direction flags */
383 >        if ( !(ap->corral>>(int)(ang*(16./PI)) & 1) )
384 >                return(0);
385 >        /*
386 >         * Generate test ray, targeting 20 degrees above sample point plane
387 >         * along surface normal from cache position.  This should be high
388 >         * enough to miss local geometry we don't really care about.
389 >         */
390 >        VSUB(vdif, ap->pos, r->rop);
391 >        normdot = DOT(anorm, r->ron);
392 >        ndotd = DOT(vdif, r->ron);
393 >        nadotd = DOT(vdif, anorm);
394 >        a = normdot*normdot - cost70sq;
395 >        b = 2.0*(normdot*ndotd - nadotd*cost70sq);
396 >        c = ndotd*ndotd - DOT(vdif,vdif)*cost70sq;
397 >        if (quadratic(t, a, b, c) != 2)
398 >                return(1);                      /* should rarely happen */
399 >        if (t[1] <= FTINY)
400 >                return(0);                      /* should fail behind test */
401 >        rayorigin(&rtst, SHADOW, r, NULL);
402 >        VSUM(rtst.rdir, vdif, anorm, t[1]);     /* further dist. > plane */
403 >        rtst.rmax = normalize(rtst.rdir);       /* short ray test */
404 >        while (localhit(&rtst, &thescene)) {    /* check for occluder */
405 >                if (rtst.ro->omod != OVOID &&
406 >                                (rtst.clipset == NULL ||
407 >                                        !inset(rtst.clipset, rtst.ro->omod)))
408 >                        return(1);              /* plug light leak */
409 >                VCOPY(rtst.rorg, rtst.rop);     /* skip invisible surface */
410 >                rtst.rmax -= rtst.rot;
411 >                rayclear(&rtst);
412 >        }
413 >        return(0);                              /* seems we're OK */
414 > }
415 >
416 >
417 > static double
418   sumambient(             /* get interpolated ambient value */
419          COLOR  acol,
420          RAY  *r,
# Line 352 | Line 424 | sumambient(            /* get interpolated ambient value */
424          FVECT  c0,
425          double  s
426   )
427 < {                                       /* initial limit is ambacc radians */
428 <        const double    maxangle = (ambacc-PI/2.)*pow(r->rweight,0.13) + PI/2.;
427 > {                       /* initial limit is 10 degrees plus ambacc radians */
428 >        const double    minangle = 10.0 * PI/180.;
429 >        double          maxangle = minangle + ambacc;
430          double          wsum = 0.0;
431          FVECT           ck0;
432          int             i, j;
433          AMBVAL          *av;
434 +
435 +        if (at->kid != NULL) {          /* sum children first */                                
436 +                s *= 0.5;
437 +                for (i = 0; i < 8; i++) {
438 +                        for (j = 0; j < 3; j++) {
439 +                                ck0[j] = c0[j];
440 +                                if (1<<j & i)
441 +                                        ck0[j] += s;
442 +                                if (r->rop[j] < ck0[j] - OCTSCALE*s)
443 +                                        break;
444 +                                if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
445 +                                        break;
446 +                        }
447 +                        if (j == 3)
448 +                                wsum += sumambient(acol, r, rn, al,
449 +                                                        at->kid+i, ck0, s);
450 +                }
451 +                                        /* good enough? */
452 +                if (wsum >= 0.05 && s > minarad*10.0)
453 +                        return(wsum);
454 +        }
455 +                                        /* adjust maximum angle */
456 +        if (at->alist != NULL && (at->alist->lvl <= al) & (r->rweight < 0.6))
457 +                maxangle = (maxangle - PI/2.)*pow(r->rweight,0.13) + PI/2.;
458                                          /* sum this node */
459          for (av = at->alist; av != NULL; av = av->next) {
460 <                double  d, delta_r2, delta_t2;
460 >                double  u, v, d, delta_r2, delta_t2;
461                  COLOR   ct;
462                  FVECT   uvw[3];
463                                          /* record access */
# Line 369 | Line 466 | sumambient(            /* get interpolated ambient value */
466                  /*
467                   *  Ambient level test
468                   */
469 <                if (av->lvl > al)       /* list sorted, so this works */
469 >                if (av->lvl > al ||     /* list sorted, so this works */
470 >                                (av->lvl == al) & (av->weight < 0.9*r->rweight))
471                          break;
374                if (av->weight < 0.9*r->rweight)
375                        continue;
472                  /*
473                   *  Direction test using unperturbed normal
474                   */
# Line 384 | Line 480 | sumambient(            /* get interpolated ambient value */
480                  if (delta_r2 >= maxangle*maxangle)
481                          continue;
482                  /*
483 +                 *  Modified ray behind test
484 +                 */
485 +                VSUB(ck0, r->rop, av->pos);
486 +                d = DOT(ck0, uvw[2]);
487 +                if (d < -minarad*ambacc-.001)
488 +                        continue;
489 +                d /= av->rad[0];
490 +                delta_t2 = d*d;
491 +                if (delta_t2 >= ambacc*ambacc)
492 +                        continue;
493 +                /*
494                   *  Elliptical radii test based on Hessian
495                   */
496                  decodedir(uvw[0], av->udir);
497                  VCROSS(uvw[1], uvw[2], uvw[0]);
498 <                VSUB(ck0, av->pos, r->rop);
392 <                d = DOT(ck0, uvw[0]) / av->rad[0];
393 <                delta_t2 = d*d;
394 <                d = DOT(ck0, uvw[1]) / av->rad[1];
498 >                d = (u = DOT(ck0, uvw[0])) / av->rad[0];
499                  delta_t2 += d*d;
500 +                d = (v = DOT(ck0, uvw[1])) / av->rad[1];
501 +                delta_t2 += d*d;
502                  if (delta_t2 >= ambacc*ambacc)
503                          continue;
504                  /*
505 <                 *  Intersection behind test
505 >                 *  Test for potential light leak
506                   */
507 <                d = 0.0;
402 <                for (j = 0; j < 3; j++)
403 <                        d += (r->rop[j] - av->pos[j])*(uvw[2][j] + r->ron[j]);
404 <                if (d*0.5 < -minarad*ambacc-.001)
507 >                if (av->corral && plugaleak(r, av, uvw[2], atan2a(v,u)))
508                          continue;
509                  /*
510                   *  Extrapolate value and compute final weight (hat function)
511                   */
512 <                extambient(ct, av, r->rop, rn, uvw);
512 >                if (!extambient(ct, av, r->rop, rn, uvw))
513 >                        continue;
514                  d = tfunc(maxangle, sqrt(delta_r2), 0.0) *
515                          tfunc(ambacc, sqrt(delta_t2), 0.0);
516                  scalecolor(ct, d);
517                  addcolor(acol, ct);
518                  wsum += d;
519          }
416        if (at->kid == NULL)
417                return(wsum);
418                                        /* sum children */
419        s *= 0.5;
420        for (i = 0; i < 8; i++) {
421                for (j = 0; j < 3; j++) {
422                        ck0[j] = c0[j];
423                        if (1<<j & i)
424                                ck0[j] += s;
425                        if (r->rop[j] < ck0[j] - OCTSCALE*s)
426                                break;
427                        if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
428                                break;
429                }
430                if (j == 3)
431                        wsum += sumambient(acol, r, rn, al,
432                                                at->kid+i, ck0, s);
433        }
520          return(wsum);
521   }
522  
523  
524 < int
524 > static int
525   makeambient(            /* make a new ambient value for storage */
526          COLOR  acol,
527          RAY  *r,
# Line 454 | Line 540 | makeambient(           /* make a new ambient value for storage
540                  amb.weight = 1.25*r->rweight;
541          setcolor(acol, AVGREFL, AVGREFL, AVGREFL);
542                                                  /* compute ambient */
543 <        if (!doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir)) {
544 <                setcolor(acol, 0.0, 0.0, 0.0);
459 <                return(0);
460 <        }
543 >        i = doambient(acol, r, amb.weight,
544 >                        uvw, amb.rad, amb.gpos, amb.gdir, &amb.corral);
545          scalecolor(acol, 1./AVGREFL);           /* undo assumed reflectance */
546 +        if (i <= 0 || amb.rad[0] <= FTINY)      /* no Hessian or zero radius */
547 +                return(i);
548                                                  /* store value */
549          VCOPY(amb.pos, r->rop);
550          amb.ndir = encodedir(r->ron);
# Line 475 | Line 561 | makeambient(           /* make a new ambient value for storage
561   }
562  
563  
564 < void
564 > static int
565   extambient(             /* extrapolate value at pv, nv */
566          COLOR  cr,
567          AMBVAL   *ap,
# Line 484 | Line 570 | extambient(            /* extrapolate value at pv, nv */
570          FVECT  uvw[3]
571   )
572   {
573 +        const double    min_d = 0.05;
574          static FVECT    my_uvw[3];
575          FVECT           v1;
576          int             i;
# Line 503 | Line 590 | extambient(            /* extrapolate value at pv, nv */
590          for (i = 3; i--; )
591                  d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]);
592          
593 <        if (d <= 0.0) {
594 <                setcolor(cr, 0.0, 0.0, 0.0);
508 <                return;
509 <        }
593 >        if (d < min_d)                  /* should not use if we can avoid it */
594 >                d = min_d;
595          copycolor(cr, ap->val);
596          scalecolor(cr, d);
597 +        return(d > min_d);
598   }
599  
600  
# Line 545 | Line 631 | avinsert(                              /* insert ambient value in our tree */
631          }
632          avh.next = at->alist;           /* order by increasing level */
633          for (ap = &avh; ap->next != NULL; ap = ap->next)
634 <                if (ap->next->lvl >= av->lvl)
634 >                if ( ap->next->lvl > av->lvl ||
635 >                                (ap->next->lvl == av->lvl) &
636 >                                (ap->next->weight <= av->weight) )
637                          break;
638          av->next = ap->next;
639          ap->next = (AMBVAL*)av;
# Line 569 | Line 657 | multambient(           /* compute ambient component & multiply
657   )
658   {
659          static int  rdepth = 0;                 /* ambient recursion */
660 <        COLOR   acol;
660 >        COLOR   acol, caustic;
661          double  d, l;
662  
663 +        /* PMAP: Factor in ambient from global photon map (if enabled) and return
664 +         * as all ambient components accounted for */
665 +        if (ambPmap(aval, r, rdepth))
666 +                return;
667 +
668 +        /* PMAP: Otherwise factor in ambient from caustic photon map
669 +         * (ambPmapCaustic() returns zero if caustic photons disabled) and
670 +         * continue with RADIANCE ambient calculation */
671 +        copycolor(caustic, aval);
672 +        ambPmapCaustic(caustic, r, rdepth);
673 +        
674          if (ambdiv <= 0)                        /* no ambient calculation */
675                  goto dumbamb;
676                                                  /* check number of bounces */
# Line 589 | Line 688 | multambient(           /* compute ambient component & multiply
688                  rdepth--;
689                  if (d <= FTINY)
690                          goto dumbamb;
691 <                copycolor(aval, acol);
691 >                copycolor(aval, acol);          
692 >        
693 >           /* PMAP: add in caustic */
694 >                addcolor(aval, caustic);        
695                  return;
696          }
697  
# Line 599 | Line 701 | multambient(           /* compute ambient component & multiply
701          setcolor(acol, 0.0, 0.0, 0.0);
702          d = sumambient(acol, r, nrm, rdepth,
703                          &atrunk, thescene.cuorg, thescene.cusize);
704 +                        
705          if (d > FTINY) {
706                  d = 1.0/d;
707                  scalecolor(acol, d);
708                  multcolor(aval, acol);
709 +                
710 +                /* PMAP: add in caustic */
711 +                addcolor(aval, caustic);        
712                  return;
713          }
714 +        
715          rdepth++;                               /* need to cache new value */
716          d = makeambient(acol, r, nrm, rdepth-1);
717          rdepth--;
718 +        
719          if (d > FTINY) {
720                  multcolor(aval, acol);          /* got new value */
721 +
722 +                /* PMAP: add in caustic */
723 +                addcolor(aval, caustic);                        
724                  return;
725          }
726 +        
727   dumbamb:                                        /* return global value */
728          if ((ambvwt <= 0) | (navsum == 0)) {
729                  multcolor(aval, ambval);
730 +
731 +                /* PMAP: add in caustic */
732 +                addcolor(aval, caustic);        
733                  return;
734          }
735 +        
736          l = bright(ambval);                     /* average in computations */
737          if (l > FTINY) {
738                  d = (log(l)*(double)ambvwt + avsum) /
# Line 658 | Line 774 | sumambient(    /* get interpolated ambient value */
774                  /*
775                   *  Ambient level test.
776                   */
777 <                if (av->lvl > al)       /* list sorted, so this works */
777 >                if (av->lvl > al ||     /* list sorted, so this works */
778 >                                (av->lvl == al) & (av->weight < 0.9*r->rweight))
779                          break;
663                if (av->weight < 0.9*r->rweight)
664                        continue;
780                  /*
781                   *  Ambient radius test.
782                   */
# Line 843 | Line 958 | avinsert(                              /* insert ambient value in our tree */
958          }
959          avh.next = at->alist;           /* order by increasing level */
960          for (ap = &avh; ap->next != NULL; ap = ap->next)
961 <                if (ap->next->lvl >= av->lvl)
961 >                if ( ap->next->lvl > av->lvl ||
962 >                                (ap->next->lvl == av->lvl) &
963 >                                (ap->next->weight <= av->weight) )
964                          break;
965          av->next = ap->next;
966          ap->next = (AMBVAL*)av;
# Line 895 | Line 1012 | avsave(                                /* insert and save an ambient value */
1012          AMBVAL  *av
1013   )
1014   {
1015 <        avinsert(avstore(av));
1015 >        avstore(av);
1016          if (ambfp == NULL)
1017                  return;
1018          if (writambval(av, ambfp) < 0)
# Line 910 | Line 1027 | writerr:
1027  
1028  
1029   static AMBVAL *
1030 < avstore(                                /* allocate memory and store aval */
1030 > avstore(                                /* allocate memory and save aval */
1031          AMBVAL  *aval
1032   )
1033   {
# Line 928 | Line 1045 | avstore(                               /* allocate memory and store aval */
1045                  avsum += log(d);
1046                  navsum++;
1047          }
1048 +        avinsert(av);                   /* insert in our cache tree */
1049          return(av);
1050   }
1051  
# Line 1106 | Line 1224 | sortambvals(                   /* resort ambient values */
1224                          oldatrunk = atrunk;
1225                          atrunk.alist = NULL;
1226                          atrunk.kid = NULL;
1227 <                        unloadatree(&oldatrunk, &avinsert);
1227 >                        unloadatree(&oldatrunk, avinsert);
1228                  }
1229          } else {                        /* sort memory by last access time */
1230                  /*
# Line 1123 | Line 1241 | sortambvals(                   /* resort ambient values */
1241                  eputs(errmsg);
1242   #endif
1243                  i_avlist = 0;
1244 <                unloadatree(&atrunk, &av2list); /* empty current tree */
1244 >                unloadatree(&atrunk, av2list);  /* empty current tree */
1245   #ifdef DEBUG
1246                  if (i_avlist < nambvals)
1247                          error(CONSISTENCY, "missing ambient values in sortambvals");
1248   #endif
1249 <                qsort((char *)avlist1, nambvals, sizeof(struct avl), &alatcmp);
1250 <                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), &aposcmp);
1249 >                qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp);
1250 >                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp);
1251                  for (i = 0; i < nambvals; i++) {
1252                          if (avlist1[i].p == NULL)
1253                                  continue;
# Line 1210 | Line 1328 | ambsync(void)                  /* synchronize ambient file */
1328                                  error(WARNING, errmsg);
1329                                  break;
1330                          }
1331 <                        avinsert(avstore(&avs));
1331 >                        avstore(&avs);
1332                          n -= AMBVALSIZ;
1333                  }
1334                  lastpos = flen - n;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines