ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/freeobjmem.c
Revision: 2.9
Committed: Mon Dec 9 17:56:25 2013 UTC (10 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad4R2, rad4R2P1, rad5R3
Changes since 2.8: +7 -7 lines
Log Message:
Added check for references to identically-named but different modifiers

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: freeobjmem.c,v 2.8 2011/02/18 00:40:25 greg Exp $";
3 #endif
4 /*
5 * Free memory associated with object(s)
6 *
7 * External symbols declared in ray.h
8 */
9
10 #include "copyright.h"
11
12 #include "ray.h"
13 #include "otypes.h"
14 #include "rtotypes.h"
15 #include "bsdf.h"
16 #include "face.h"
17 #include "cone.h"
18 #include "instance.h"
19 #include "data.h"
20 #include "font.h"
21 #include "func.h"
22 #include "mesh.h"
23
24
25 int
26 free_os( /* free unneeded memory for object */
27 OBJREC *op
28 )
29 {
30 if (op->os == NULL)
31 return(0);
32 if (hasfunc(op->otype)) {
33 freefunc(op);
34 return(1);
35 }
36 switch (op->otype) {
37 case OBJ_FACE: /* polygon */
38 freeface(op);
39 return(1);
40 case OBJ_CONE: /* cone */
41 case OBJ_RING: /* disk */
42 case OBJ_CYLINDER: /* cylinder */
43 case OBJ_CUP: /* inverted cone */
44 case OBJ_TUBE: /* inverted cylinder */
45 freecone(op);
46 return(1);
47 case OBJ_INSTANCE: /* octree instance */
48 freeinstance(op);
49 return(1);
50 case OBJ_MESH: /* mesh instance */
51 freemeshinst(op);
52 return(1);
53 case PAT_BTEXT: /* monochromatic text */
54 case PAT_CTEXT: /* colored text */
55 case MIX_TEXT: /* mixing text */
56 freetext(op);
57 return(1);
58 case MAT_CLIP: /* clipping surface */
59 case MAT_SPOT: /* spot light source */
60 free((void *)op->os);
61 op->os = NULL;
62 return(1);
63 }
64 #ifdef DEBUG
65 objerror(op, WARNING, "cannot free structure");
66 #endif
67 return(0);
68 }
69
70
71 int
72 free_objs( /* free some object structures */
73 OBJECT on,
74 OBJECT no
75 )
76 {
77 int nfreed;
78 OBJREC *op;
79
80 for (nfreed = 0; no-- > 0; on++) {
81 op = objptr(on);
82 if (op->os != NULL)
83 nfreed += free_os(op);
84 }
85 return(nfreed);
86 }
87
88
89 void
90 free_objmem(void) /* free all object cache memory */
91 {
92 free_objs(0, nobjects);
93 freedata(NULL);
94 freefont(NULL);
95 SDfreeCache(NULL);
96 }