From 7b7aba31f24d51c904c76a17ee50608b770e1bc9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 2 Nov 2015 21:37:15 +1100 Subject: Fix T46626: Crash generating previews Brush.toggle_brush was allowed to be an invalid pointer, it worked for the one operator that used it - but in general bad practice, requiring a lookup on every access. Ensure the pointer is kept valid now. --- source/blender/blenkernel/intern/brush.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source/blender/blenkernel/intern/brush.c') diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index c2a66adbf92..95b65f52bd0 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -223,11 +223,27 @@ void BKE_brush_free(Brush *brush) MEM_freeN(brush->gradient); } +/** + * \note Currently users don't remove brushes from the UI (as is done for scene, text... etc) + * This is only used by RNA, which can remove brushes. + */ +void BKE_brush_unlink(Main *bmain, Brush *brush) +{ + Brush *brush_iter; + + for (brush_iter = bmain->brush.first; brush_iter; brush_iter = brush_iter->id.next) { + if (brush_iter->toggle_brush == brush) { + brush_iter->toggle_brush = NULL; + } + } +} + static void extern_local_brush(Brush *brush) { id_lib_extern((ID *)brush->mtex.tex); id_lib_extern((ID *)brush->mask_mtex.tex); id_lib_extern((ID *)brush->clone.image); + id_lib_extern((ID *)brush->toggle_brush); id_lib_extern((ID *)brush->paint_curve); } -- cgit v1.2.3