Back to index

radiance  4R0+20100331
freeobjmem.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: freeobjmem.c,v 2.7 2004/03/30 16:13:01 schorsch Exp $";
00003 #endif
00004 /*
00005  * Free memory associated with object(s)
00006  *
00007  * External symbols declared in ray.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include "ray.h"
00013 #include "otypes.h"
00014 #include "rtotypes.h"
00015 #include "face.h"
00016 #include "cone.h"
00017 #include "instance.h"
00018 #include "data.h"
00019 #include "font.h"
00020 #include "func.h"
00021 #include "mesh.h"
00022 
00023 
00024 extern int
00025 free_os(                    /* free unneeded memory for object */
00026        register OBJREC      *op
00027 )
00028 {
00029        if (op->os == NULL)
00030               return(0);
00031        if (hasfunc(op->otype)) {
00032               freefunc(op);
00033               return(1);
00034        }
00035        switch (op->otype) {
00036        case OBJ_FACE:              /* polygon */
00037               freeface(op);
00038               return(1);
00039        case OBJ_CONE:              /* cone */
00040        case OBJ_RING:              /* disk */
00041        case OBJ_CYLINDER:   /* cylinder */
00042        case OBJ_CUP:        /* inverted cone */
00043        case OBJ_TUBE:              /* inverted cylinder */
00044               freecone(op);
00045               return(1);
00046        case OBJ_INSTANCE:   /* octree instance */
00047               freeinstance(op);
00048               return(1);
00049        case OBJ_MESH:              /* mesh instance */
00050               freemeshinst(op);
00051               return(1);
00052        case PAT_BTEXT:             /* monochromatic text */
00053        case PAT_CTEXT:             /* colored text */
00054        case MIX_TEXT:              /* mixing text */
00055               freetext(op);
00056               return(1);
00057        case MAT_CLIP:              /* clipping surface */
00058        case MAT_SPOT:              /* spot light source */
00059               free((void *)op->os);
00060               op->os = NULL;
00061               return(1);
00062        }
00063 #ifdef DEBUG
00064        objerror(op, WARNING, "cannot free structure");
00065 #endif
00066        return(0);
00067 }
00068 
00069 
00070 extern int
00071 free_objs(           /* free some object structures */
00072        register OBJECT      on,
00073        OBJECT no
00074 )
00075 {
00076        int    nfreed;
00077        register OBJREC      *op;
00078 
00079        for (nfreed = 0; no-- > 0; on++) {
00080               op = objptr(on);
00081               if (op->os != NULL)
00082                      nfreed += free_os(op);
00083        }
00084        return(nfreed);
00085 }
00086 
00087 
00088 extern void
00089 free_objmem(void)                  /* free all object cache memory */
00090 {
00091        free_objs(0, nobjects);
00092        freedata(NULL);
00093        freefont(NULL);
00094 }