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.80 by greg, Fri Apr 25 18:38:47 2014 UTC vs.
Revision 2.99 by greg, Thu Mar 3 22:44:10 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 52 | Line 51 | static int  nunflshed = 0;     /* number of unflushed ambi
51   #endif
52  
53  
55 static double  qambacc = 0.;            /* ambient accuracy to the 1/4 power */
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 110 | 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 129 | 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);
137 <        if (ambdiff >= .01 && (ambacc = newa) > FTINY) {
138 <                qambacc = sqrt(sqrt(ambacc));
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          }
# Line 152 | Line 148 | setambient(void)                               /* initialize calculation */
148          ambdone();
149                                                  /* init ambient limits */
150          setambres(ambres);
151 <        qambacc = sqrt(sqrt(ambacc *= (ambacc > FTINY)));
151 >        setambacc(ambacc);
152          if (ambfile == NULL || !ambfile[0])
153                  return;
154          if (ambacc <= FTINY) {
# Line 168 | 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 200 | Line 196 | setambient(void)                               /* initialize calculation */
196                  sprintf(errmsg, "cannot open ambient file \"%s\"", ambfile);
197                  error(SYSTEM, errmsg);
198          }
203 #ifdef getc_unlocked
204        flockfile(ambfp);                       /* application-level lock */
205 #endif
199   #ifdef  F_SETLKW
200          aflock(F_UNLCK);                        /* release file */
201   #endif
# Line 223 | Line 216 | ambdone(void)                  /* close ambient file and free memory
216                  lastpos = -1;
217          }
218                                          /* free ambient tree */
219 <        unloadatree(&atrunk, &avfree);
219 >        unloadatree(&atrunk, avfree);
220 >        freeambtree(NULL);
221                                          /* reset state variables */
222          avsum = 0.;
223          navsum = 0;
# Line 266 | Line 260 | ambnotify(                     /* record new modifier */
260  
261   /************ THE FOLLOWING ROUTINES DIFFER BETWEEN NEW & OLD ***************/
262  
263 < #ifdef NEWAMB
263 > #ifndef OLDAMB
264  
265   #define tfunc(lwr, x, upr)      (((x)-(lwr))/((upr)-(lwr)))
266  
267 + static int      plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang);
268   static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
269                                  AMBTREE *at, FVECT c0, double s);
270   static int      makeambient(COLOR acol, RAY *r, FVECT rn, int al);
271 < static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
271 > static int      extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
272                                  FVECT uvw[3]);
273  
274   void
# Line 284 | Line 279 | multambient(           /* compute ambient component & multiply
279   )
280   {
281          static int  rdepth = 0;                 /* ambient recursion */
282 <        COLOR   acol;
282 >        COLOR   acol, caustic;
283          int     ok;
284          double  d, l;
285  
286 +        /* PMAP: Factor in ambient from photon map, if enabled and ray is
287 +         * ambient. Return as all ambient components accounted for, else
288 +         * continue. */
289 +        if (ambPmap(aval, r, rdepth))
290 +                return;
291 +
292 +        /* PMAP: Factor in specular-diffuse ambient (caustics) from photon
293 +         * map, if enabled and ray is primary, else caustic is zero.  Continue
294 +         * with RADIANCE ambient calculation */
295 +        copycolor(caustic, aval);
296 +        ambPmapCaustic(caustic, r, rdepth);
297 +        
298          if (ambdiv <= 0)                        /* no ambient calculation */
299                  goto dumbamb;
300                                                  /* check number of bounces */
# Line 301 | Line 308 | multambient(           /* compute ambient component & multiply
308          if (ambacc <= FTINY) {                  /* no ambient storage */
309                  copycolor(acol, aval);
310                  rdepth++;
311 <                ok = doambient(acol, r, r->rweight, NULL, NULL, NULL, NULL);
311 >                ok = doambient(acol, r, r->rweight,
312 >                                NULL, NULL, NULL, NULL, NULL);
313                  rdepth--;
314                  if (!ok)
315                          goto dumbamb;
316                  copycolor(aval, acol);
317 +
318 +                /* PMAP: add in caustic */
319 +                addcolor(aval, caustic);
320                  return;
321          }
322  
# Line 315 | Line 326 | multambient(           /* compute ambient component & multiply
326          setcolor(acol, 0.0, 0.0, 0.0);
327          d = sumambient(acol, r, nrm, rdepth,
328                          &atrunk, thescene.cuorg, thescene.cusize);
329 +                        
330          if (d > FTINY) {
331                  d = 1.0/d;
332                  scalecolor(acol, d);
333                  multcolor(aval, acol);
334 +
335 +                /* PMAP: add in caustic */
336 +                addcolor(aval, caustic);
337                  return;
338          }
339 +        
340          rdepth++;                               /* need to cache new value */
341          ok = makeambient(acol, r, nrm, rdepth-1);
342          rdepth--;
343 +        
344          if (ok) {
345                  multcolor(aval, acol);          /* computed new value */
346 +
347 +                /* PMAP: add in caustic */
348 +                addcolor(aval, caustic);
349                  return;
350          }
351 +        
352   dumbamb:                                        /* return global value */
353          if ((ambvwt <= 0) | (navsum == 0)) {
354                  multcolor(aval, ambval);
355 +                
356 +                /* PMAP: add in caustic */
357 +                addcolor(aval, caustic);
358                  return;
359          }
360 <        l = bright(ambval);                     /* average in computations */
360 >        
361 >        l = bright(ambval);                     /* average in computations */  
362          if (l > FTINY) {
363                  d = (log(l)*(double)ambvwt + avsum) /
364                                  (double)(ambvwt + navsum);
# Line 347 | Line 372 | dumbamb:                                       /* return global value */
372   }
373  
374  
375 < double
375 > /* Plug a potential leak where ambient cache value is occluded */
376 > static int
377 > plugaleak(RAY *r, AMBVAL *ap, FVECT anorm, double ang)
378 > {
379 >        const double    cost70sq = 0.1169778;   /* cos(70deg)^2 */
380 >        RAY             rtst;
381 >        FVECT           vdif;
382 >        double          normdot, ndotd, nadotd;
383 >        double          a, b, c, t[2];
384 >
385 >        ang += 2.*PI*(ang < 0);                 /* check direction flags */
386 >        if ( !(ap->corral>>(int)(ang*(16./PI)) & 1) )
387 >                return(0);
388 >        /*
389 >         * Generate test ray, targeting 20 degrees above sample point plane
390 >         * along surface normal from cache position.  This should be high
391 >         * enough to miss local geometry we don't really care about.
392 >         */
393 >        VSUB(vdif, ap->pos, r->rop);
394 >        normdot = DOT(anorm, r->ron);
395 >        ndotd = DOT(vdif, r->ron);
396 >        nadotd = DOT(vdif, anorm);
397 >        a = normdot*normdot - cost70sq;
398 >        b = 2.0*(normdot*ndotd - nadotd*cost70sq);
399 >        c = ndotd*ndotd - DOT(vdif,vdif)*cost70sq;
400 >        if (quadratic(t, a, b, c) != 2)
401 >                return(1);                      /* should rarely happen */
402 >        if (t[1] <= FTINY)
403 >                return(0);                      /* should fail behind test */
404 >        rayorigin(&rtst, SHADOW, r, NULL);
405 >        VSUM(rtst.rdir, vdif, anorm, t[1]);     /* further dist. > plane */
406 >        rtst.rmax = normalize(rtst.rdir);       /* short ray test */
407 >        while (localhit(&rtst, &thescene)) {    /* check for occluder */
408 >                if (rtst.ro->omod != OVOID &&
409 >                                (rtst.clipset == NULL ||
410 >                                        !inset(rtst.clipset, rtst.ro->omod)))
411 >                        return(1);              /* plug light leak */
412 >                VCOPY(rtst.rorg, rtst.rop);     /* skip invisible surface */
413 >                rtst.rmax -= rtst.rot;
414 >                rayclear(&rtst);
415 >        }
416 >        return(0);                              /* seems we're OK */
417 > }
418 >
419 >
420 > static double
421   sumambient(             /* get interpolated ambient value */
422          COLOR  acol,
423          RAY  *r,
# Line 359 | Line 429 | sumambient(            /* get interpolated ambient value */
429   )
430   {                       /* initial limit is 10 degrees plus ambacc radians */
431          const double    minangle = 10.0 * PI/180.;
432 <        const double    maxangle = (minangle+ambacc-PI/2.)*pow(r->rweight,0.13)
363 <                                        + PI/2.;
432 >        double          maxangle = minangle + ambacc;
433          double          wsum = 0.0;
434          FVECT           ck0;
435          int             i, j;
436          AMBVAL          *av;
437 +
438 +        if (at->kid != NULL) {          /* sum children first */                                
439 +                s *= 0.5;
440 +                for (i = 0; i < 8; i++) {
441 +                        for (j = 0; j < 3; j++) {
442 +                                ck0[j] = c0[j];
443 +                                if (1<<j & i)
444 +                                        ck0[j] += s;
445 +                                if (r->rop[j] < ck0[j] - OCTSCALE*s)
446 +                                        break;
447 +                                if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
448 +                                        break;
449 +                        }
450 +                        if (j == 3)
451 +                                wsum += sumambient(acol, r, rn, al,
452 +                                                        at->kid+i, ck0, s);
453 +                }
454 +                                        /* good enough? */
455 +                if (wsum >= 0.05 && s > minarad*10.0)
456 +                        return(wsum);
457 +        }
458 +                                        /* adjust maximum angle */
459 +        if (at->alist != NULL && (at->alist->lvl <= al) & (r->rweight < 0.6))
460 +                maxangle = (maxangle - PI/2.)*pow(r->rweight,0.13) + PI/2.;
461                                          /* sum this node */
462          for (av = at->alist; av != NULL; av = av->next) {
463 <                double  d, delta_r2, delta_t2;
463 >                double  u, v, d, delta_r2, delta_t2;
464                  COLOR   ct;
465                  FVECT   uvw[3];
466                                          /* record access */
# Line 376 | Line 469 | sumambient(            /* get interpolated ambient value */
469                  /*
470                   *  Ambient level test
471                   */
472 <                if (av->lvl > al)       /* list sorted, so this works */
472 >                if (av->lvl > al ||     /* list sorted, so this works */
473 >                                (av->lvl == al) & (av->weight < 0.9*r->rweight))
474                          break;
381                if (av->weight < 0.9*r->rweight)
382                        continue;
475                  /*
476                   *  Direction test using unperturbed normal
477                   */
# Line 391 | Line 483 | sumambient(            /* get interpolated ambient value */
483                  if (delta_r2 >= maxangle*maxangle)
484                          continue;
485                  /*
486 +                 *  Modified ray behind test
487 +                 */
488 +                VSUB(ck0, r->rop, av->pos);
489 +                d = DOT(ck0, uvw[2]);
490 +                if (d < -minarad*ambacc-.001)
491 +                        continue;
492 +                d /= av->rad[0];
493 +                delta_t2 = d*d;
494 +                if (delta_t2 >= ambacc*ambacc)
495 +                        continue;
496 +                /*
497                   *  Elliptical radii test based on Hessian
498                   */
499                  decodedir(uvw[0], av->udir);
500                  VCROSS(uvw[1], uvw[2], uvw[0]);
501 <                VSUB(ck0, av->pos, r->rop);
399 <                d = DOT(ck0, uvw[0]) / av->rad[0];
400 <                delta_t2 = d*d;
401 <                d = DOT(ck0, uvw[1]) / av->rad[1];
501 >                d = (u = DOT(ck0, uvw[0])) / av->rad[0];
502                  delta_t2 += d*d;
503 <                d = DOT(ck0, uvw[2]) / av->rad[0];
503 >                d = (v = DOT(ck0, uvw[1])) / av->rad[1];
504                  delta_t2 += d*d;
505 <                if (delta_t2 >= qambacc*qambacc)
505 >                if (delta_t2 >= ambacc*ambacc)
506                          continue;
507                  /*
508 +                 *  Test for potential light leak
509 +                 */
510 +                if (av->corral && plugaleak(r, av, uvw[2], atan2a(v,u)))
511 +                        continue;
512 +                /*
513                   *  Extrapolate value and compute final weight (hat function)
514                   */
515 <                extambient(ct, av, r->rop, rn, uvw);
515 >                if (!extambient(ct, av, r->rop, rn, uvw))
516 >                        continue;
517                  d = tfunc(maxangle, sqrt(delta_r2), 0.0) *
518 <                        tfunc(qambacc, sqrt(delta_t2), 0.0);
518 >                        tfunc(ambacc, sqrt(delta_t2), 0.0);
519                  scalecolor(ct, d);
520                  addcolor(acol, ct);
521                  wsum += d;
522          }
417        if (at->kid == NULL)
418                return(wsum);
419                                        /* sum children */
420        s *= 0.5;
421        for (i = 0; i < 8; i++) {
422                for (j = 0; j < 3; j++) {
423                        ck0[j] = c0[j];
424                        if (1<<j & i)
425                                ck0[j] += s;
426                        if (r->rop[j] < ck0[j] - OCTSCALE*s)
427                                break;
428                        if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s)
429                                break;
430                }
431                if (j == 3)
432                        wsum += sumambient(acol, r, rn, al,
433                                                at->kid+i, ck0, s);
434        }
523          return(wsum);
524   }
525  
526  
527 < int
527 > static int
528   makeambient(            /* make a new ambient value for storage */
529          COLOR  acol,
530          RAY  *r,
# Line 455 | Line 543 | makeambient(           /* make a new ambient value for storage
543                  amb.weight = 1.25*r->rweight;
544          setcolor(acol, AVGREFL, AVGREFL, AVGREFL);
545                                                  /* compute ambient */
546 <        i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir);
546 >        i = doambient(acol, r, amb.weight,
547 >                        uvw, amb.rad, amb.gpos, amb.gdir, &amb.corral);
548          scalecolor(acol, 1./AVGREFL);           /* undo assumed reflectance */
549          if (i <= 0 || amb.rad[0] <= FTINY)      /* no Hessian or zero radius */
550                  return(i);
# Line 475 | Line 564 | makeambient(           /* make a new ambient value for storage
564   }
565  
566  
567 < void
567 > static int
568   extambient(             /* extrapolate value at pv, nv */
569          COLOR  cr,
570          AMBVAL   *ap,
# Line 484 | Line 573 | extambient(            /* extrapolate value at pv, nv */
573          FVECT  uvw[3]
574   )
575   {
576 +        const double    min_d = 0.05;
577          static FVECT    my_uvw[3];
578          FVECT           v1;
579          int             i;
# Line 503 | Line 593 | extambient(            /* extrapolate value at pv, nv */
593          for (i = 3; i--; )
594                  d += v1[i] * (ap->gdir[0]*uvw[0][i] + ap->gdir[1]*uvw[1][i]);
595          
596 <        if (d <= 0.0) {
597 <                setcolor(cr, 0.0, 0.0, 0.0);
508 <                return;
509 <        }
596 >        if (d < min_d)                  /* should not use if we can avoid it */
597 >                d = min_d;
598          copycolor(cr, ap->val);
599          scalecolor(cr, d);
600 +        return(d > min_d);
601   }
602  
603  
# Line 530 | Line 619 | avinsert(                              /* insert ambient value in our tree */
619          at = &atrunk;
620          VCOPY(ck0, thescene.cuorg);
621          s = thescene.cusize;
622 <        while (s*(OCTSCALE/2) > av->rad[1]*qambacc) {
622 >        while (s*(OCTSCALE/2) > av->rad[1]*ambacc) {
623                  if (at->kid == NULL)
624                          if ((at->kid = newambtree()) == NULL)
625                                  error(SYSTEM, "out of memory in avinsert");
# Line 545 | Line 634 | avinsert(                              /* insert ambient value in our tree */
634          }
635          avh.next = at->alist;           /* order by increasing level */
636          for (ap = &avh; ap->next != NULL; ap = ap->next)
637 <                if (ap->next->lvl >= av->lvl)
637 >                if ( ap->next->lvl > av->lvl ||
638 >                                (ap->next->lvl == av->lvl) &
639 >                                (ap->next->weight <= av->weight) )
640                          break;
641          av->next = ap->next;
642          ap->next = (AMBVAL*)av;
# Line 569 | Line 660 | multambient(           /* compute ambient component & multiply
660   )
661   {
662          static int  rdepth = 0;                 /* ambient recursion */
663 <        COLOR   acol;
663 >        COLOR   acol, caustic;
664          double  d, l;
665  
666 +        /* PMAP: Factor in ambient from global photon map (if enabled) and return
667 +         * as all ambient components accounted for */
668 +        if (ambPmap(aval, r, rdepth))
669 +                return;
670 +
671 +        /* PMAP: Otherwise factor in ambient from caustic photon map
672 +         * (ambPmapCaustic() returns zero if caustic photons disabled) and
673 +         * continue with RADIANCE ambient calculation */
674 +        copycolor(caustic, aval);
675 +        ambPmapCaustic(caustic, r, rdepth);
676 +        
677          if (ambdiv <= 0)                        /* no ambient calculation */
678                  goto dumbamb;
679                                                  /* check number of bounces */
# Line 589 | Line 691 | multambient(           /* compute ambient component & multiply
691                  rdepth--;
692                  if (d <= FTINY)
693                          goto dumbamb;
694 <                copycolor(aval, acol);
694 >                copycolor(aval, acol);          
695 >        
696 >           /* PMAP: add in caustic */
697 >                addcolor(aval, caustic);        
698                  return;
699          }
700  
# Line 599 | Line 704 | multambient(           /* compute ambient component & multiply
704          setcolor(acol, 0.0, 0.0, 0.0);
705          d = sumambient(acol, r, nrm, rdepth,
706                          &atrunk, thescene.cuorg, thescene.cusize);
707 +                        
708          if (d > FTINY) {
709                  d = 1.0/d;
710                  scalecolor(acol, d);
711                  multcolor(aval, acol);
712 +                
713 +                /* PMAP: add in caustic */
714 +                addcolor(aval, caustic);        
715                  return;
716          }
717 +        
718          rdepth++;                               /* need to cache new value */
719          d = makeambient(acol, r, nrm, rdepth-1);
720          rdepth--;
721 +        
722          if (d > FTINY) {
723                  multcolor(aval, acol);          /* got new value */
724 +
725 +                /* PMAP: add in caustic */
726 +                addcolor(aval, caustic);                        
727                  return;
728          }
729 +        
730   dumbamb:                                        /* return global value */
731          if ((ambvwt <= 0) | (navsum == 0)) {
732                  multcolor(aval, ambval);
733 +
734 +                /* PMAP: add in caustic */
735 +                addcolor(aval, caustic);        
736                  return;
737          }
738 +        
739          l = bright(ambval);                     /* average in computations */
740          if (l > FTINY) {
741                  d = (log(l)*(double)ambvwt + avsum) /
# Line 658 | Line 777 | sumambient(    /* get interpolated ambient value */
777                  /*
778                   *  Ambient level test.
779                   */
780 <                if (av->lvl > al)       /* list sorted, so this works */
780 >                if (av->lvl > al ||     /* list sorted, so this works */
781 >                                (av->lvl == al) & (av->weight < 0.9*r->rweight))
782                          break;
663                if (av->weight < 0.9*r->rweight)
664                        continue;
783                  /*
784                   *  Ambient radius test.
785                   */
# Line 843 | Line 961 | avinsert(                              /* insert ambient value in our tree */
961          }
962          avh.next = at->alist;           /* order by increasing level */
963          for (ap = &avh; ap->next != NULL; ap = ap->next)
964 <                if (ap->next->lvl >= av->lvl)
964 >                if ( ap->next->lvl > av->lvl ||
965 >                                (ap->next->lvl == av->lvl) &
966 >                                (ap->next->weight <= av->weight) )
967                          break;
968          av->next = ap->next;
969          ap->next = (AMBVAL*)av;
# Line 895 | Line 1015 | avsave(                                /* insert and save an ambient value */
1015          AMBVAL  *av
1016   )
1017   {
1018 <        avinsert(avstore(av));
1018 >        avstore(av);
1019          if (ambfp == NULL)
1020                  return;
1021          if (writambval(av, ambfp) < 0)
# Line 910 | Line 1030 | writerr:
1030  
1031  
1032   static AMBVAL *
1033 < avstore(                                /* allocate memory and store aval */
1033 > avstore(                                /* allocate memory and save aval */
1034          AMBVAL  *aval
1035   )
1036   {
# Line 928 | Line 1048 | avstore(                               /* allocate memory and store aval */
1048                  avsum += log(d);
1049                  navsum++;
1050          }
1051 +        avinsert(av);                   /* insert in our cache tree */
1052          return(av);
1053   }
1054  
# Line 964 | Line 1085 | freeambtree(                   /* free 8 ambient tree structs */
1085          AMBTREE  *atp
1086   )
1087   {
1088 <        atp->kid = atfreelist;
1088 >        if (atp == NULL) {      /* freeing free list? */
1089 >                while ((atp = atfreelist) != NULL) {
1090 >                        atfreelist = atp->kid;
1091 >                        free(atp);
1092 >                }
1093 >                return;
1094 >        }
1095 >        atp->kid = atfreelist;  /* else push node onto free list */
1096          atfreelist = atp;
1097   }
1098  
# Line 1106 | Line 1234 | sortambvals(                   /* resort ambient values */
1234                          oldatrunk = atrunk;
1235                          atrunk.alist = NULL;
1236                          atrunk.kid = NULL;
1237 <                        unloadatree(&oldatrunk, &avinsert);
1237 >                        unloadatree(&oldatrunk, avinsert);
1238                  }
1239          } else {                        /* sort memory by last access time */
1240                  /*
# Line 1123 | Line 1251 | sortambvals(                   /* resort ambient values */
1251                  eputs(errmsg);
1252   #endif
1253                  i_avlist = 0;
1254 <                unloadatree(&atrunk, &av2list); /* empty current tree */
1254 >                unloadatree(&atrunk, av2list);  /* empty current tree */
1255   #ifdef DEBUG
1256                  if (i_avlist < nambvals)
1257                          error(CONSISTENCY, "missing ambient values in sortambvals");
1258   #endif
1259 <                qsort((char *)avlist1, nambvals, sizeof(struct avl), &alatcmp);
1260 <                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), &aposcmp);
1259 >                qsort((char *)avlist1, nambvals, sizeof(struct avl), alatcmp);
1260 >                qsort((char *)avlist2, nambvals, sizeof(AMBVAL *), aposcmp);
1261                  for (i = 0; i < nambvals; i++) {
1262                          if (avlist1[i].p == NULL)
1263                                  continue;
# Line 1210 | Line 1338 | ambsync(void)                  /* synchronize ambient file */
1338                                  error(WARNING, errmsg);
1339                                  break;
1340                          }
1341 <                        avinsert(avstore(&avs));
1341 >                        avstore(&avs);
1342                          n -= AMBVALSIZ;
1343                  }
1344                  lastpos = flen - n;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines