bugfix for grease pencil freeing order.
authorCampbell Barton <ideasman42@gmail.com>
Fri, 29 Oct 2010 07:11:45 +0000 (07:11 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 29 Oct 2010 07:11:45 +0000 (07:11 +0000)
it was freed before objects which would then decrease its usercount - accessing freed memory.

Also fixed error in own last commit.

source/blender/blenkernel/intern/library.c
source/blender/makesrna/intern/rna_image.c

index dfc82152e8c17d64eed95465e48372284699004a..dc3c120ab19b19d72dccf84625f9af9d71e26811 100644 (file)
@@ -452,11 +452,13 @@ int set_listbasepointers(Main *main, ListBase **lb)
 {
        int a = 0;
 
-       /* BACKWARDS! also watch order of free-ing! (mesh<->mat) */
-
+       /* BACKWARDS! also watch order of free-ing! (mesh<->mat), first items freed last.
+        * This is important because freeing data decreases usercounts of other datablocks,
+        * if this data is its self freed it can crash. */
        lb[a++]= &(main->ipo);
        lb[a++]= &(main->action); // xxx moved here to avoid problems when freeing with animato (aligorith)
        lb[a++]= &(main->key);
+       lb[a++]= &(main->gpencil); /* referenced by nodes, objects, view, scene etc, before to free after. */
        lb[a++]= &(main->nodetree);
        lb[a++]= &(main->image);
        lb[a++]= &(main->tex);
@@ -483,14 +485,13 @@ int set_listbasepointers(Main *main, ListBase **lb)
        lb[a++]= &(main->brush);
        lb[a++]= &(main->script);
        lb[a++]= &(main->particle);
-       
+
        lb[a++]= &(main->world);
        lb[a++]= &(main->screen);
        lb[a++]= &(main->object);
        lb[a++]= &(main->scene);
        lb[a++]= &(main->library);
        lb[a++]= &(main->wm);
-       lb[a++]= &(main->gpencil);
        
        lb[a]= NULL;
 
index 4ac7624e73150e4bd40b12556e5117ab1df5d0b2..62e7b516e9e985379b3f3c4d935bde70fe585768 100644 (file)
@@ -181,7 +181,7 @@ static void rna_Image_file_format_set(PointerRNA *ptr, int value)
                */
 
                /* to be safe change all buffer file types */
-               for(ibuf= image->ibufs.first; ibuf; ibuf->next) {
+               for(ibuf= image->ibufs.first; ibuf; ibuf= ibuf->next) {
                        ibuf->ftype= ftype;
                }
        }