Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-11-02 13:37:15 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-11-02 13:42:47 +0300
commit7b7aba31f24d51c904c76a17ee50608b770e1bc9 (patch)
tree326c218109d49fe285579ace7e4097643a9a8cdc
parent7a9693fa8ba2132e09a892dfa0e60736b741002a (diff)
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.
-rw-r--r--source/blender/blenkernel/BKE_brush.h1
-rw-r--r--source/blender/blenkernel/intern/brush.c16
-rw-r--r--source/blender/blenloader/intern/readfile.c2
-rw-r--r--source/blender/editors/sculpt_paint/paint_ops.c7
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c1
5 files changed, 22 insertions, 5 deletions
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index bb3ad0efb63..fd566f34f2e 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -45,6 +45,7 @@ struct Brush *BKE_brush_add(struct Main *bmain, const char *name, short ob_mode)
struct Brush *BKE_brush_first_search(struct Main *bmain, short ob_mode);
struct Brush *BKE_brush_copy(struct Brush *brush);
void BKE_brush_make_local(struct Brush *brush);
+void BKE_brush_unlink(struct Main *bmain, struct Brush *brush);
void BKE_brush_free(struct Brush *brush);
void BKE_brush_sculpt_reset(struct Brush *brush);
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);
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 92925eeb425..604f6436af1 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2162,6 +2162,7 @@ static void lib_link_brush(FileData *fd, Main *main)
brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex);
brush->mask_mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mask_mtex.tex);
brush->clone.image = newlibadr_us(fd, brush->id.lib, brush->clone.image);
+ brush->toggle_brush = newlibadr(fd, brush->id.lib, brush->toggle_brush);
brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve);
}
}
@@ -8819,6 +8820,7 @@ static void expand_brush(FileData *fd, Main *mainvar, Brush *brush)
expand_doit(fd, mainvar, brush->mtex.tex);
expand_doit(fd, mainvar, brush->mask_mtex.tex);
expand_doit(fd, mainvar, brush->clone.image);
+ expand_doit(fd, mainvar, brush->toggle_brush);
expand_doit(fd, mainvar, brush->paint_curve);
}
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index cee92abe03d..bfeac6219c7 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -407,12 +407,9 @@ static Brush *brush_tool_toggle(Main *bmain, Brush *brush_orig, const int tool,
return br;
}
- else if (brush_orig->toggle_brush &&
- BLI_findindex(bmain->brush.first, brush_orig->toggle_brush) != -1)
- {
+ else if (brush_orig->toggle_brush) {
/* if current brush is using the desired tool, try to toggle
- * back to the previously selected brush (if it was set, and
- * if it still exists) */
+ * back to the previously selected brush. */
return brush_orig->toggle_brush;
}
else
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 8e28b35b0ed..057fed50c32 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -504,6 +504,7 @@ static void rna_Main_brushes_remove(Main *bmain, ReportList *reports, PointerRNA
{
Brush *brush = brush_ptr->data;
if (ID_REAL_USERS(brush) <= 0) {
+ BKE_brush_unlink(bmain, brush);
BKE_libblock_free(bmain, brush);
RNA_POINTER_INVALIDATE(brush_ptr);
}