|
From: Peep P. <so...@us...> - 2004-07-24 17:50:40
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31140 Modified Files: object.c Log Message: apply_create() Index: object.c =================================================================== RCS file: /cvsroot/agd/server/src/object.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- object.c 23 Jul 2004 17:06:43 -0000 1.19 +++ object.c 24 Jul 2004 17:50:31 -0000 1.20 @@ -20,6 +20,8 @@ player_t *this_player; object_t *this_ob, *previous_ob; +int doing_load; + extern program_t *compile_prog(char *path); void free_fun(void *p) @@ -52,7 +54,12 @@ for(p=&ob->refs;p->next;p=p->next) { variable_t *v = p->data; - v->u.ob = NULL; + if(v->u.ob == ob) + v->u.ob = NULL; + else { + if(conf.debuglevel) + printf("object's ref is not to object!\n"); + } } list_remove(&all_objects, ob); @@ -102,8 +109,11 @@ list_remove(&ob->refs, v); ob->numref--; if(ob->numref <= 0) { + /* Here we swap them out. */ +#if 0 printf("refs for %s = 0\n", ob->name); destruct(ob); +#endif } } @@ -160,6 +170,21 @@ return NULL; } +void apply_create(object_t **ob, int already_in) +{ + doing_load = 1; + apply(*ob, "create", NULL); + if(doing_load) { + doing_load = 0; + } else { + /* A runtime error happened in create(). */ + if(already_in) + list_remove(&all_objects, *ob); + free(*ob); + *ob = NULL; + } +} + object_t *load_object(char *path) { object_t *ob, @@ -167,10 +192,12 @@ *saved_prev_ob; player_t *saved_tp; +#if 0 if(!legal_path(path)) { printf("load_object(): illegal path name \"%s\"!\n", path); return NULL; } +#endif saved_this_ob = this_ob; saved_prev_ob = previous_ob; @@ -193,7 +220,8 @@ saved_tp = this_player; this_player = NULL; - apply(ob, "create", NULL); + doing_load = 1; + apply_create(&ob, 1); goto out; } } @@ -212,11 +240,11 @@ goto out; } - list_push(&all_objects, ob); - saved_tp = this_player; this_player = NULL; - apply(ob, "create", NULL); + apply_create(&ob, 0); + if(ob) + list_push(&all_objects, ob); out: this_player = saved_tp; @@ -249,7 +277,8 @@ ref_prog(new_ob->prog); new_ob->numglobals = base_ob->numglobals; - new_ob->globals = xmalloc(sizeof(variable_t) * new_ob->numglobals); + if(new_ob->numglobals) + new_ob->globals = xmalloc(sizeof(variable_t) * new_ob->numglobals); for(i=0;i<new_ob->numglobals;i++) { variable_t *v = &new_ob->globals[i]; *v = base_ob->globals[i]; @@ -257,9 +286,9 @@ v->name = xstrdup(v->name); } - apply(new_ob, "create", NULL); - list_push(&all_objects, new_ob); - + apply_create(&new_ob, 0); + if(new_ob) + list_push(&all_objects, new_ob); return new_ob; } |