From 9be6880d020eb2a6891c07e0b8794400f20f5464 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 11 Nov 2021 14:29:14 +0100 Subject: Fix (unreported) bad handling of reports in `libraries.load` code. rB60fee69682ac39 only partially fixed the issue, `BlendFileReadReport bf_reports` was now properly stored in `BPy_Library` `self` for the lifetime of the context, but its `reports` member was still referencing local variable to `bpy_lib_enter` function. --- source/blender/python/intern/bpy_library_load.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c index d9a357c5e2e..059d692a9ba 100644 --- a/source/blender/python/intern/bpy_library_load.c +++ b/source/blender/python/intern/bpy_library_load.c @@ -67,7 +67,9 @@ typedef struct { char abspath[FILE_MAX]; /* absolute path */ BlendHandle *blo_handle; /* Referenced by `blo_handle`, so stored here to keep alive for long enough. */ + ReportList reports; BlendFileReadReport bf_reports; + int flag; PyObject *dict; /* Borrowed reference to the `bmain`, taken from the RNA instance of #RNA_BlendDataLibraries. @@ -256,16 +258,17 @@ static PyObject *bpy_lib_enter(BPy_Library *self) PyObject *ret; BPy_Library *self_from; PyObject *from_dict = _PyDict_NewPresized(INDEX_ID_MAX); - ReportList reports; + ReportList *reports = &self->reports; + BlendFileReadReport *bf_reports = &self->bf_reports; - BKE_reports_init(&reports, RPT_STORE); - BlendFileReadReport bf_reports = {.reports = &reports}; + BKE_reports_init(reports, RPT_STORE); + memset(bf_reports, 0, sizeof(*bf_reports)); + bf_reports->reports = reports; - self->bf_reports = bf_reports; - self->blo_handle = BLO_blendhandle_from_file(self->abspath, &self->bf_reports); + self->blo_handle = BLO_blendhandle_from_file(self->abspath, bf_reports); if (self->blo_handle == NULL) { - if (BPy_reports_to_error(&reports, PyExc_IOError, true) != -1) { + if (BPy_reports_to_error(reports, PyExc_IOError, true) != -1) { PyErr_Format(PyExc_IOError, "load: %s failed to open blend file", self->abspath); } return NULL; @@ -301,7 +304,7 @@ static PyObject *bpy_lib_enter(BPy_Library *self) PyTuple_SET_ITEMS(ret, (PyObject *)self_from, (PyObject *)self); Py_INCREF(self); - BKE_reports_clear(&reports); + BKE_reports_clear(reports); return ret; } -- cgit v1.2.3