Fix T49856: Blender 2.78 crashes after loading data from a blendfile

Issue here was that py API code was keeping references (pointers) to the
liniked data-blocks, which can actually be duplicated and then deleted
during the 'make local' process...

Would have like to find a better way than passing optional GHash to get
the oldid->newid mapping, but could not think of a better idea.
This commit is contained in:
2016-11-01 13:39:31 +01:00
parent bf1e9bc613
commit 1ee43c5aef
6 changed files with 20 additions and 8 deletions

View File

@@ -33,6 +33,7 @@
#include <stddef.h>
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
#include "BLI_string.h"
#include "BLI_linklist.h"
#include "BLI_path_util.h"
@@ -405,6 +406,8 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
BLO_blendhandle_close(self->blo_handle);
self->blo_handle = NULL;
GHash *old_to_new_ids = BLI_ghash_ptr_new(__func__);
/* copied from wm_operator.c */
{
/* mark all library linked objects to be updated */
@@ -412,7 +415,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
/* append, rather than linking */
if ((self->flag & FILE_LINK) == 0) {
BKE_library_make_local(bmain, lib, true, false);
BKE_library_make_local(bmain, lib, old_to_new_ids, true, false);
}
}
@@ -439,6 +442,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
ID *id;
id = PyCapsule_GetPointer(item, NULL);
id = BLI_ghash_lookup_default(old_to_new_ids, id, id);
Py_DECREF(item);
RNA_id_pointer_create(id, &id_ptr);
@@ -452,6 +456,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
}
#endif /* USE_RNA_DATABLOCKS */
BLI_ghash_free(old_to_new_ids, NULL, NULL);
Py_RETURN_NONE;
}
}