diff --git a/source/blender/blenkernel/BKE_paint.hh b/source/blender/blenkernel/BKE_paint.hh index e0031de88f8..a5f5ae14959 100644 --- a/source/blender/blenkernel/BKE_paint.hh +++ b/source/blender/blenkernel/BKE_paint.hh @@ -173,7 +173,7 @@ PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name); /** * Call when entering each respective paint mode. */ -bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint); +bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint); void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3]); void BKE_paint_free(Paint *p); /** @@ -188,7 +188,7 @@ void BKE_paint_runtime_init(const ToolSettings *ts, Paint *paint); void BKE_paint_cavity_curve_preset(Paint *p, int preset); eObjectMode BKE_paint_object_mode_from_paintmode(PaintMode mode); -bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode); +bool BKE_paint_ensure_from_paintmode(Main *bmain, Scene *sce, PaintMode mode); Paint *BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode); const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(PaintMode mode); const char *BKE_paint_get_tool_enum_translation_context_from_paintmode(PaintMode mode); @@ -732,7 +732,7 @@ void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, Main *bmain, Object *ob, MultiresModifierData *mmd); -void BKE_sculpt_toolsettings_data_ensure(Scene *scene); +void BKE_sculpt_toolsettings_data_ensure(Main *bmain, Scene *scene); PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob); diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc index 8a423fb2b8d..86a3b8f2506 100644 --- a/source/blender/blenkernel/intern/paint.cc +++ b/source/blender/blenkernel/intern/paint.cc @@ -326,7 +326,7 @@ void BKE_paint_reset_overlay_invalid(ePaintOverlayControlFlags flag) overlay_flags &= ~(flag); } -bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode) +bool BKE_paint_ensure_from_paintmode(Main *bmain, Scene *sce, PaintMode mode) { ToolSettings *ts = sce->toolsettings; Paint **paint_ptr = nullptr; @@ -371,7 +371,7 @@ bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode) break; } if (paint_ptr) { - BKE_paint_ensure(ts, paint_ptr); + BKE_paint_ensure(bmain, ts, paint_ptr); return true; } return false; @@ -1091,7 +1091,7 @@ eObjectMode BKE_paint_object_mode_from_paintmode(const PaintMode mode) } } -bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint) +bool BKE_paint_ensure(Main * /*bmain*/, ToolSettings *ts, Paint **r_paint) { Paint *paint = nullptr; if (*r_paint) { @@ -1176,7 +1176,7 @@ void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3]) UnifiedPaintSettings *ups = &sce->toolsettings->unified_paint_settings; Paint *paint = BKE_paint_get_active_from_paintmode(sce, mode); - BKE_paint_ensure_from_paintmode(sce, mode); + BKE_paint_ensure_from_paintmode(bmain, sce, mode); /* If there's no brush, create one */ Brush *brush = BKE_paint_brush(paint); @@ -2001,9 +2001,9 @@ void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, } } -void BKE_sculpt_toolsettings_data_ensure(Scene *scene) +void BKE_sculpt_toolsettings_data_ensure(Main *bmain, Scene *scene) { - BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->sculpt); + BKE_paint_ensure(bmain, scene->toolsettings, (Paint **)&scene->toolsettings->sculpt); Sculpt *sd = scene->toolsettings->sculpt; diff --git a/source/blender/blenloader/intern/versioning_280.cc b/source/blender/blenloader/intern/versioning_280.cc index 838b94fef0f..e80008b7da7 100644 --- a/source/blender/blenloader/intern/versioning_280.cc +++ b/source/blender/blenloader/intern/versioning_280.cc @@ -2874,10 +2874,10 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain) ToolSettings *ts = scene->toolsettings; /* Ensure new Paint modes. */ - BKE_paint_ensure_from_paintmode(scene, PaintMode::GPencil); - BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil); - BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil); - BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::GPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil); /* Set default Draw brush. */ if (brush != nullptr) { @@ -2918,9 +2918,9 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain) /* Reset all grease pencil brushes. */ LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { /* Ensure new Paint modes. */ - BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil); - BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil); - BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil); } } diff --git a/source/blender/blenloader/intern/versioning_defaults.cc b/source/blender/blenloader/intern/versioning_defaults.cc index e8b21374209..e14ab31b536 100644 --- a/source/blender/blenloader/intern/versioning_defaults.cc +++ b/source/blender/blenloader/intern/versioning_defaults.cc @@ -555,9 +555,9 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) } /* Ensure new Paint modes. */ - BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil); - BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil); - BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil); + BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil); /* Enable cursor. */ if (ts->gp_paint) { diff --git a/source/blender/editors/gpencil_legacy/gpencil_edit.cc b/source/blender/editors/gpencil_legacy/gpencil_edit.cc index fb431d9a9ad..9ae116ec6a0 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_edit.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_edit.cc @@ -420,8 +420,8 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op) if (mode == OB_MODE_PAINT_GPENCIL_LEGACY) { /* Be sure we have brushes and Paint settings. * Need Draw and Vertex (used for Tint). */ - BKE_paint_ensure(ts, (Paint **)&ts->gp_paint); - BKE_paint_ensure(ts, (Paint **)&ts->gp_vertexpaint); + BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint); + BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_vertexpaint); BKE_brush_gpencil_paint_presets(bmain, ts, false); @@ -572,7 +572,7 @@ static int gpencil_sculptmode_toggle_exec(bContext *C, wmOperator *op) if (mode == OB_MODE_SCULPT_GPENCIL_LEGACY) { /* Be sure we have brushes. */ - BKE_paint_ensure(ts, (Paint **)&ts->gp_sculptpaint); + BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_sculptpaint); const bool reset_mode = (BKE_paint_brush(&ts->gp_sculptpaint->paint) == nullptr); BKE_brush_gpencil_sculpt_presets(bmain, ts, reset_mode); @@ -711,7 +711,7 @@ static int gpencil_weightmode_toggle_exec(bContext *C, wmOperator *op) if (mode == OB_MODE_WEIGHT_GPENCIL_LEGACY) { /* Be sure we have brushes. */ Paint *weight_paint = BKE_paint_get_active_from_paintmode(scene, PaintMode::WeightGPencil); - BKE_paint_ensure(ts, &weight_paint); + BKE_paint_ensure(bmain, ts, &weight_paint); if (ob->type == OB_GREASE_PENCIL) { ED_paint_cursor_start(weight_paint, grease_pencil_poll_weight_cursor); @@ -829,8 +829,8 @@ static int gpencil_vertexmode_toggle_exec(bContext *C, wmOperator *op) if (mode == OB_MODE_VERTEX_GPENCIL_LEGACY) { /* Be sure we have brushes. * Need Draw as well (used for Palettes). */ - BKE_paint_ensure(ts, (Paint **)&ts->gp_paint); - BKE_paint_ensure(ts, (Paint **)&ts->gp_vertexpaint); + BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint); + BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_vertexpaint); const bool reset_mode = (BKE_paint_brush(&ts->gp_vertexpaint->paint) == nullptr); BKE_brush_gpencil_vertex_presets(bmain, ts, reset_mode); diff --git a/source/blender/editors/gpencil_legacy/gpencil_utils.cc b/source/blender/editors/gpencil_legacy/gpencil_utils.cc index cff07ac327b..6c505caf73e 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_utils.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_utils.cc @@ -1428,7 +1428,7 @@ void ED_gpencil_add_defaults(bContext *C, Object *ob) Main *bmain = CTX_data_main(C); ToolSettings *ts = CTX_data_tool_settings(C); - BKE_paint_ensure(ts, (Paint **)&ts->gp_paint); + BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint); Paint *paint = &ts->gp_paint->paint; Brush *brush = BKE_paint_brush(paint); /* if not exist, create a new one */ diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc index 7d3650b7906..f4a7d74012a 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc @@ -282,7 +282,8 @@ static void curves_sculptmode_enter(bContext *C) wmMsgBus *mbus = CTX_wm_message_bus(C); Object *ob = CTX_data_active_object(C); - BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->curves_sculpt); + BKE_paint_ensure( + CTX_data_main(C), scene->toolsettings, (Paint **)&scene->toolsettings->curves_sculpt); CurvesSculpt *curves_sculpt = scene->toolsettings->curves_sculpt; ob->mode = OB_MODE_SCULPT_CURVES; diff --git a/source/blender/editors/sculpt_paint/paint_intern.hh b/source/blender/editors/sculpt_paint/paint_intern.hh index ada7790ddc9..7f3a96cbc15 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.hh +++ b/source/blender/editors/sculpt_paint/paint_intern.hh @@ -556,7 +556,8 @@ void get_brush_alpha_data(const Scene *scene, void init_stroke(Depsgraph *depsgraph, Object *ob); void init_session_data(const ToolSettings *ts, Object *ob); -void init_session(Depsgraph *depsgraph, Scene *scene, Object *ob, eObjectMode object_mode); +void init_session( + Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, eObjectMode object_mode); Vector pbvh_gather_generic(Object *ob, VPaint *wp, Brush *brush); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index 3cfec6786f9..891bcb1dc13 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -214,10 +214,11 @@ void init_stroke(Depsgraph *depsgraph, Object *ob) } /* Toggle operator for turning vertex paint mode on or off (copied from sculpt.cc) */ -void init_session(Depsgraph *depsgraph, Scene *scene, Object *ob, eObjectMode object_mode) +void init_session( + Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, eObjectMode object_mode) { /* Create persistent sculpt mode data */ - BKE_sculpt_toolsettings_data_ensure(scene); + BKE_sculpt_toolsettings_data_ensure(bmain, scene); BLI_assert(ob->sculpt == nullptr); ob->sculpt = MEM_new(__func__); @@ -321,7 +322,7 @@ void mode_enter_generic( const PaintMode paint_mode = PaintMode::Vertex; ED_mesh_color_ensure(mesh, nullptr); - BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->vpaint); + BKE_paint_ensure(bmain, scene->toolsettings, (Paint **)&scene->toolsettings->vpaint); Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); ED_paint_cursor_start(paint, vertex_paint_poll); BKE_paint_init(bmain, scene, paint_mode, PAINT_CURSOR_VERTEX_PAINT); @@ -329,7 +330,7 @@ void mode_enter_generic( else if (mode_flag == OB_MODE_WEIGHT_PAINT) { const PaintMode paint_mode = PaintMode::Weight; - BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->wpaint); + BKE_paint_ensure(bmain, scene->toolsettings, (Paint **)&scene->toolsettings->wpaint); Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); ED_paint_cursor_start(paint, weight_paint_poll); BKE_paint_init(bmain, scene, paint_mode, PAINT_CURSOR_WEIGHT_PAINT); @@ -351,7 +352,7 @@ void mode_enter_generic( BKE_sculptsession_free(ob); } - vwpaint::init_session(depsgraph, scene, ob, mode_flag); + vwpaint::init_session(bmain, depsgraph, scene, ob, mode_flag); /* Flush object mode. */ DEG_id_tag_update(&ob->id, ID_RECALC_SYNC_TO_EVAL); diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.cc b/source/blender/editors/sculpt_paint/sculpt_ops.cc index 03cf3d84499..59d2fe791a8 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -280,7 +280,7 @@ namespace blender::ed::sculpt_paint { static void sculpt_init_session(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob) { /* Create persistent sculpt mode data. */ - BKE_sculpt_toolsettings_data_ensure(scene); + BKE_sculpt_toolsettings_data_ensure(bmain, scene); /* Create sculpt mode session data. */ if (ob->sculpt != nullptr) { diff --git a/source/blender/windowmanager/intern/wm_toolsystem.cc b/source/blender/windowmanager/intern/wm_toolsystem.cc index a4233b3d3ee..e0b192d46a8 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.cc +++ b/source/blender/windowmanager/intern/wm_toolsystem.cc @@ -187,7 +187,7 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { if (workspace == WM_window_get_active_workspace(win)) { Scene *scene = WM_window_get_active_scene(win); - BKE_paint_ensure_from_paintmode(scene, paint_mode); + BKE_paint_ensure_from_paintmode(bmain, scene, paint_mode); Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); Brush *brush = BKE_paint_toolslots_brush_get(paint, slot_index); if (brush == nullptr) {