Fix T70714: Crash when using OBJECT_OT_material_slot_assign op without UI.

There is no guarantee we can get any valid UI from the context, and that
operator can work without it.
This commit is contained in:
Bastien Montagne 2019-10-11 17:13:11 +02:00
parent 1e5e65fa9f
commit 1c2a20c84d
Notes: blender-bot 2023-02-14 01:52:41 +01:00
Referenced by issue #70714, Problem with bpy.ops.object.material_slot_assign () when running a script from the console
1 changed files with 8 additions and 6 deletions

View File

@ -103,15 +103,17 @@ static Object **object_array_for_shading(bContext *C, uint *r_objects_len)
ScrArea *sa = CTX_wm_area(C);
SpaceProperties *sbuts = NULL;
View3D *v3d = NULL;
if (sa->spacetype == SPACE_PROPERTIES) {
sbuts = sa->spacedata.first;
}
else if (sa->spacetype == SPACE_VIEW3D) {
v3d = sa->spacedata.first;
if (sa != NULL) {
if (sa->spacetype == SPACE_PROPERTIES) {
sbuts = sa->spacedata.first;
}
else if (sa->spacetype == SPACE_VIEW3D) {
v3d = sa->spacedata.first;
}
}
Object **objects;
if (sbuts && sbuts->pinid && GS(sbuts->pinid->name) == ID_OB) {
if (sbuts != NULL && sbuts->pinid && GS(sbuts->pinid->name) == ID_OB) {
objects = MEM_mallocN(sizeof(*objects), __func__);
objects[0] = (Object *)sbuts->pinid;
*r_objects_len = 1;