--- ray/src/common/instance.c 1991/05/29 17:11:32 1.7 +++ ray/src/common/instance.c 1994/04/14 04:44:47 2.4 @@ -16,6 +16,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "instance.h" +#define IO_ILLEGAL (IO_FILES|IO_INFO) + static SCENE *slist = NULL; /* list of loaded octrees */ @@ -24,11 +26,11 @@ getscene(sname, flags) /* load octree sname */ char *sname; int flags; { - extern char *libpath; + extern char *getlibpath(); char *pathname; register SCENE *sc; - flags &= ~(IO_FILES|IO_INFO); /* not allowed */ + flags &= ~IO_ILLEGAL; /* not allowed */ for (sc = slist; sc != NULL; sc = sc->next) if (!strcmp(sname, sc->name)) { if ((sc->ldflags & flags) == flags) @@ -41,14 +43,24 @@ int flags; error(SYSTEM, "out of memory in getscene"); sc->name = savestr(sname); sc->ldflags = 0; + sc->scube.cutree = EMPTY; + sc->scube.cuorg[0] = sc->scube.cuorg[1] = + sc->scube.cuorg[2] = 0.; + sc->scube.cusize = 0.; + sc->firstobj = sc->nobjs = 0; sc->next = slist; slist = sc; } - if ((pathname = getpath(sname, libpath, R_OK)) == NULL) { + if ((pathname = getpath(sname, getlibpath(), R_OK)) == NULL) { sprintf(errmsg, "cannot find octree file \"%s\"", sname); error(USER, errmsg); } - readoct(pathname, flags & ~sc->ldflags, &sc->scube, NULL); + flags &= ~sc->ldflags; /* skip what's already loaded */ + if (flags & IO_SCENE) + sc->firstobj = nobjects; + readoct(pathname, flags, &sc->scube, NULL); + if (flags & IO_SCENE) + sc->nobjs = nobjects - sc->firstobj; sc->ldflags |= flags; return(sc); } @@ -61,6 +73,7 @@ int flags; { register INSTANCE *in; + flags &= ~IO_ILLEGAL; /* not allowed */ if ((in = (INSTANCE *)o->os) == NULL) { if ((in = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL) error(SYSTEM, "out of memory in getinstance"); @@ -85,5 +98,8 @@ int flags; freeinstance(o) /* free memory associated with instance */ OBJREC *o; { + if (o->os == NULL) + return; free(o->os); + o->os = NULL; }