Index: src/object.c
===================================================================
--- src/object.c	(Revision 2312)
+++ src/object.c	(Arbeitskopie)
@@ -448,7 +448,7 @@
 
 /*-------------------------------------------------------------------------*/
 void
-init_object_variables (object_t *ob)
+init_object_variables (object_t *ob, object_t *templ)
 
 /* The variables of object <ob> are initialized.
  * First, if <ob> is a clone, all variables marked as !VAR_INITIALIZED are
@@ -463,20 +463,14 @@
     /* For clones, copy the shared variable values */
     if ((ob->flags & O_CLONE))
     {
-        object_t *bp;
         int i;
         variable_t *p_vars;
         svalue_t *ob_vars, *bp_vars;
 
-        bp = ob->prog->blueprint;
-        if (!bp || bp->flags & O_DESTRUCTED)
-        {
-            if (bp) free_object(bp, "init_object_variables");
-            ob->prog->blueprint = NULL;
+        if (!templ || templ->flags & O_DESTRUCTED)
             bp_vars = NULL;
-        }
         else
-            bp_vars = bp->variables;
+            bp_vars = templ->variables;
 
         ob_vars = ob->variables;
         p_vars = ob->prog->variables;
@@ -1065,6 +1059,16 @@
             r_ob->ob->variables = new_vars;
         } /* if (change in vars) */
 
+        /* If this is a blueprint object, NULL out the pointer in the program,
+         * because this isn't the blueprint for this program anymore.
+         */
+        if (r_ob->ob->prog->blueprint == r_ob->ob)
+        {
+            r_ob->ob->prog->blueprint = NULL;
+            remove_prog_swap(r_ob->ob->prog, MY_TRUE);
+            free_object(r_ob->ob, "replace_programs: blueprint reference");
+        }
+        
         /* Replace the old program with the new one */
         old_prog = r_ob->ob->prog;
         r_ob->new_prog->ref++;
Index: src/object.h
===================================================================
--- src/object.h	(Revision 2312)
+++ src/object.h	(Arbeitskopie)
@@ -295,7 +295,7 @@
 extern void dealloc_object(object_t *, const char * file, int line);
 #endif
 extern object_t *get_empty_object(int num_var);
-extern void      init_object_variables (object_t *ob);
+extern void      init_object_variables (object_t *ob, object_t *templ);
 
 extern svalue_t *v_function_exists(svalue_t *sp, int num_arg);
 extern svalue_t *f_functionlist(svalue_t *sp);
Index: src/simulate.c
===================================================================
--- src/simulate.c	(Revision 2312)
+++ src/simulate.c	(Arbeitskopie)
@@ -2117,7 +2117,7 @@
         {
             /* The master object is loaded with no current object */
             current_object = NULL;
-            init_object_variables(ob);
+            init_object_variables(ob, NULL);
             reset_object(ob, create_super ? H_CREATE_SUPER : H_CREATE_OB);
 
             /* If the master inherits anything -Ugh- we have to have
@@ -2128,7 +2128,7 @@
         else
         {
             current_object = save_current;
-            init_object_variables(ob);
+            init_object_variables(ob, NULL);
             reset_object(ob, create_super ? H_CREATE_SUPER : H_CREATE_OB);
         }
     }
@@ -2337,7 +2337,7 @@
     push_ref_object(inter_sp, ob, "clone_object");
     push_ref_string(inter_sp, new_ob->name);
     give_uid_to_object(new_ob, H_CLONE_UIDS, 2);
-    init_object_variables(new_ob);
+    init_object_variables(new_ob, ob);
     reset_object(new_ob, H_CREATE_CLONE);
     command_giver = check_object(save_command_giver);
 
