Commit: a30bdcc142f1241a302107c637fd47be06073d76
Author: Antonioya
Date:   Thu Jan 3 18:10:39 2019 +0100
Branches: master
https://developer.blender.org/rBa30bdcc142f1241a302107c637fd47be06073d76

Fix T60022: Crash when adding grease pencil object to a collection disabled in 
viewport.

See D4163

Thanks to Habib Gahbiche (@zazizizou) for the fix.

===================================================================

M       source/blender/editors/gpencil/gpencil_add_monkey.c
M       source/blender/editors/gpencil/gpencil_add_stroke.c
M       source/blender/editors/gpencil/gpencil_data.c
M       source/blender/editors/gpencil/gpencil_utils.c
M       source/blender/editors/include/ED_gpencil.h
M       source/blender/editors/object/object_add.c

===================================================================

diff --git a/source/blender/editors/gpencil/gpencil_add_monkey.c 
b/source/blender/editors/gpencil/gpencil_add_monkey.c
index ce5d765ada4..21697995b9c 100644
--- a/source/blender/editors/gpencil/gpencil_add_monkey.c
+++ b/source/blender/editors/gpencil/gpencil_add_monkey.c
@@ -535,10 +535,9 @@ static const ColorTemplate gp_monkey_pct_pupils = {
 /* Monkey API */
 
 /* add a 2D Suzanne (original model created by Matias Mendiola) */
-void ED_gpencil_create_monkey(bContext *C, float mat[4][4])
+void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4])
 {
        Main *bmain = CTX_data_main(C);
-       Object *ob = CTX_data_active_object(C);
        Depsgraph *depsgraph = CTX_data_depsgraph(C);
        int cfra_eval = (int)DEG_get_ctime(depsgraph);
        bGPdata *gpd = (bGPdata *)ob->data;
diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c 
b/source/blender/editors/gpencil/gpencil_add_stroke.c
index 330f7a69e09..6df3638d859 100644
--- a/source/blender/editors/gpencil/gpencil_add_stroke.c
+++ b/source/blender/editors/gpencil/gpencil_add_stroke.c
@@ -213,10 +213,9 @@ static const ColorTemplate gp_stroke_material_grey = {
 /* Stroke API */
 
 /* add a Simple stroke with colors (original design created by Daniel M. Lara 
and Matias Mendiola) */
-void ED_gpencil_create_stroke(bContext *C, float mat[4][4])
+void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4])
 {
        Main *bmain = CTX_data_main(C);
-       Object *ob = CTX_data_active_object(C);
        Depsgraph *depsgraph = CTX_data_depsgraph(C);
        int cfra_eval = (int)DEG_get_ctime(depsgraph);
        bGPdata *gpd = (bGPdata *)ob->data;
diff --git a/source/blender/editors/gpencil/gpencil_data.c 
b/source/blender/editors/gpencil/gpencil_data.c
index a8cfe91740c..8afb0cafeb9 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -137,7 +137,8 @@ static int gp_data_add_exec(bContext *C, wmOperator *op)
                        *gpd_ptr = BKE_gpencil_data_addnew(bmain, 
DATA_("GPencil"));
 
                        /* add default sets of colors and brushes */
-                       ED_gpencil_add_defaults(C);
+                       Object *ob = CTX_data_active_object(C);
+                       ED_gpencil_add_defaults(C, ob);
 
                        /* add new layer */
                        BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), 
true);
@@ -245,7 +246,8 @@ static int gp_layer_add_exec(bContext *C, wmOperator *op)
                        *gpd_ptr = BKE_gpencil_data_addnew(bmain, 
DATA_("GPencil"));
 
                        /* add default sets of colors and brushes */
-                       ED_gpencil_add_defaults(C);
+                       Object *ob = CTX_data_active_object(C);
+                       ED_gpencil_add_defaults(C, ob);
                }
        }
 
diff --git a/source/blender/editors/gpencil/gpencil_utils.c 
b/source/blender/editors/gpencil/gpencil_utils.c
index 4d6a7b547c6..f7fafb56d3a 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1221,16 +1221,15 @@ Object *ED_gpencil_add_object(bContext *C, Scene 
*UNUSED(scene), const float loc
        /* define size */
        BKE_object_obdata_size_init(ob, GP_OBGPENCIL_DEFAULT_SIZE);
        /* create default brushes and colors */
-       ED_gpencil_add_defaults(C);
+       ED_gpencil_add_defaults(C, ob);
 
        return ob;
 }
 
 /* Helper function to create default colors and drawing brushes */
-void ED_gpencil_add_defaults(bContext *C)
+void ED_gpencil_add_defaults(bContext *C, Object *ob)
 {
        Main *bmain = CTX_data_main(C);
-       Object *ob = CTX_data_active_object(C);
        ToolSettings *ts = CTX_data_tool_settings(C);
 
        /* first try to reuse default material */
diff --git a/source/blender/editors/include/ED_gpencil.h 
b/source/blender/editors/include/ED_gpencil.h
index fb216a8c9a9..c231d0dc355 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -220,13 +220,13 @@ void ED_gpencil_brush_draw_eraser(struct Brush *brush, 
int x, int y);
 
 /* ----------- Add Primitive Utilities -------------- */
 
-void ED_gpencil_create_monkey(struct bContext *C, float mat[4][4]);
-void ED_gpencil_create_stroke(struct bContext *C, float mat[4][4]);
+void ED_gpencil_create_monkey(struct bContext *C, struct Object *ob, float 
mat[4][4]);
+void ED_gpencil_create_stroke(struct bContext *C, struct Object *ob, float 
mat[4][4]);
 
 /* ------------ Object Utilities ------------ */
 struct Object *ED_gpencil_add_object(
         struct bContext *C, struct Scene *scene, const float loc[3], unsigned 
short local_view_bits);
-void ED_gpencil_add_defaults(struct bContext *C);
+void ED_gpencil_add_defaults(struct bContext *C, struct Object *ob);
 /* set object modes */
 void ED_gpencil_setup_modes(struct bContext *C, struct bGPdata *gpd, int 
newmode);
 
diff --git a/source/blender/editors/object/object_add.c 
b/source/blender/editors/object/object_add.c
index 316d581870d..6be1afdcb2a 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -1030,7 +1030,7 @@ static int object_gpencil_add_exec(bContext *C, 
wmOperator *op)
                        mul_v3_fl(mat[1], radius);
                        mul_v3_fl(mat[2], radius);
 
-                       ED_gpencil_create_stroke(C, mat);
+                       ED_gpencil_create_stroke(C, ob, mat);
                        break;
                }
                case GP_MONKEY:
@@ -1043,7 +1043,7 @@ static int object_gpencil_add_exec(bContext *C, 
wmOperator *op)
                        mul_v3_fl(mat[1], radius);
                        mul_v3_fl(mat[2], radius);
 
-                       ED_gpencil_create_monkey(C, mat);
+                       ED_gpencil_create_monkey(C, ob, mat);
                        break;
                }
                case GP_EMPTY:
@@ -1057,7 +1057,7 @@ static int object_gpencil_add_exec(bContext *C, 
wmOperator *op)
 
        /* if this is a new object, initialise default stuff (colors, etc.) */
        if (newob) {
-               ED_gpencil_add_defaults(C);
+               ED_gpencil_add_defaults(C, ob);
        }
 
        return OPERATOR_FINISHED;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to