ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_alias.c
Revision: 2.4
Committed: Tue Jan 20 22:16:53 2004 UTC (20 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +13 -3 lines
Log Message:
Fixed bug where aliases with object structures were leaking memory

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: m_alias.c,v 2.3 2003/09/09 03:28:43 greg Exp $";
3 #endif
4 /*
5 * Handler for modifier alias
6 */
7
8 #include "copyright.h"
9 #include "ray.h"
10 #include "otypes.h"
11 #include "otspecial.h"
12
13 /*
14 * If the alias has a single string argument, it's the
15 * name of the target modifier, and we must substitute the
16 * target and its arguments in place of this alias. The
17 * only difference is that we use our modifier rather than
18 * theirs.
19 * If the alias has no string arguments, then we simply
20 * pass through to our modifier as if we weren't in the
21 * chain at all.
22 */
23
24 int
25 m_alias(m, r) /* transfer shading to alias target */
26 OBJREC *m;
27 RAY *r;
28 {
29 OBJECT aobj;
30 OBJREC *aop;
31 OBJREC arec;
32 int rval;
33 /* straight replacement? */
34 if (!m->oargs.nsargs)
35 return(rayshade(r, m->omod));
36 /* else replace alias */
37 if (m->oargs.nsargs != 1)
38 objerror(m, INTERNAL, "bad # string arguments");
39 aobj = lastmod(objndx(m), m->oargs.sarg[0]);
40 if (aobj < 0)
41 objerror(m, USER, "bad reference");
42 aop = objptr(aobj);
43 arec = *aop;
44 /* irradiance hack */
45 if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) &&
46 m->otype != MAT_CLIP &&
47 (ofun[arec.otype].flags & (T_M|T_X))) {
48 if (irr_ignore(arec.otype)) {
49 raytrans(r);
50 return(1);
51 }
52 if (!islight(arec.otype))
53 return((*ofun[Lamb.otype].funp)(&Lamb, r));
54 }
55 /* substitute modifier */
56 arec.omod = m->omod;
57 /* replacement shader */
58 rval = (*ofun[arec.otype].funp)(&arec, r);
59 /* save allocated struct */
60 if (arec.os != aop->os) {
61 if (aop->os != NULL) /* should never happen */
62 free_os(aop);
63 aop->os = arec.os;
64 }
65 return(rval);
66 }