ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/freeobjmem.c
Revision: 2.6
Committed: Thu Jul 10 03:47:00 2003 UTC (20 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +4 -1 lines
Log Message:
Fixed serious bug in ranimate where mesh instances were not being freed

File Contents

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