Fix T51052: CacheFile Open crashes from Python

Note that bpy.data access makes more sense here,
but better not crash when called from Python.
This commit is contained in:
Campbell Barton 2017-07-10 17:06:25 +10:00
parent c055536d23
commit 2c10e8a3cf
Notes: blender-bot 2023-02-14 19:40:57 +01:00
Referenced by issue blender/blender-addons#51052, CacheFile Open Operator Crashes Blender
1 changed files with 14 additions and 12 deletions

View File

@ -97,22 +97,24 @@ static int cachefile_open_exec(bContext *C, wmOperator *op)
BLI_strncpy(cache_file->filepath, filename, FILE_MAX);
BKE_cachefile_reload(bmain, cache_file);
/* hook into UI */
PropertyPointerRNA *pprop = op->customdata;
/* Will be set when running invoke, not exec directly. */
if (op->customdata != NULL) {
/* hook into UI */
PropertyPointerRNA *pprop = op->customdata;
if (pprop->prop) {
/* when creating new ID blocks, use is already 1, but RNA
* pointer se also increases user, so this compensates it */
id_us_min(&cache_file->id);
if (pprop->prop) {
/* when creating new ID blocks, use is already 1, but RNA
* pointer se also increases user, so this compensates it */
id_us_min(&cache_file->id);
PointerRNA idptr;
RNA_id_pointer_create(&cache_file->id, &idptr);
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
RNA_property_update(C, &pprop->ptr, pprop->prop);
}
PointerRNA idptr;
RNA_id_pointer_create(&cache_file->id, &idptr);
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
RNA_property_update(C, &pprop->ptr, pprop->prop);
MEM_freeN(op->customdata);
}
MEM_freeN(op->customdata);
return OPERATOR_FINISHED;
}