Rework/split test_object_materials().

Now test_object_materials only handles one object. New test_all_objects_materials
checks the whole bmain->object list for cases where it is actually needed.

Should avoid some useless looping over all objects!
This commit is contained in:
Bastien Montagne 2016-07-08 14:36:25 +02:00
parent 71f5df9f44
commit ab993e373c
Notes: blender-bot 2023-02-14 07:44:27 +01:00
Referenced by commit a40073ffcc, Fix use after free error from ab993e37
Referenced by issue #48898, shaders are remove from metaballs on cycles render
8 changed files with 28 additions and 15 deletions

View File

@ -47,7 +47,8 @@ struct Scene;
void init_def_material(void);
void BKE_material_free(struct Material *ma);
void BKE_material_free_ex(struct Material *ma, bool do_id_user);
void test_object_materials(struct Main *bmain, struct ID *id);
void test_object_materials(struct Object *ob, struct ID *id);
void test_all_objects_materials(struct Main *bmain, struct ID *id);
void BKE_material_resize_object(struct Object *ob, const short totcol, bool do_id_user);
void BKE_material_init(struct Material *ma);
void BKE_material_remap_object(struct Object *ob, const unsigned int *remap);

View File

@ -611,7 +611,7 @@ void BKE_material_append_id(ID *id, Material *ma)
(*matar)[(*totcol)++] = ma;
id_us_plus((ID *)ma);
test_object_materials(G.main, id);
test_all_objects_materials(G.main, id);
}
}
@ -637,7 +637,7 @@ Material *BKE_material_pop_id(ID *id, int index_i, bool update_data)
(*totcol)--;
*matar = MEM_reallocN(*matar, sizeof(void *) * (*totcol));
test_object_materials(G.main, id);
test_all_objects_materials(G.main, id);
}
if (update_data) {
@ -776,7 +776,19 @@ void BKE_material_resize_object(Object *ob, const short totcol, bool do_id_user)
if (ob->actcol > ob->totcol) ob->actcol = ob->totcol;
}
void test_object_materials(Main *bmain, ID *id)
void test_object_materials(Object *ob, ID *id)
{
/* make the ob mat-array same size as 'ob->data' mat-array */
const short *totcol;
if (id == NULL || (totcol = give_totcolp_id(id)) == NULL) {
return;
}
BKE_material_resize_object(ob, *totcol, false);
}
void test_all_objects_materials(Main *bmain, ID *id)
{
/* make the ob mat-array same size as 'ob->data' mat-array */
Object *ob;
@ -787,7 +799,7 @@ void test_object_materials(Main *bmain, ID *id)
}
BKE_main_lock(bmain);
for (ob = bmain->object.first; ob; ob = ob->id.next) {
for (bmain = bmain->object.first; ob; ob = ob->id.next) {
if (ob->data == id) {
BKE_material_resize_object(ob, *totcol, false);
}
@ -839,7 +851,7 @@ void assign_material_id(ID *id, Material *ma, short act)
if (ma)
id_us_plus(&ma->id);
test_object_materials(G.main, id);
test_all_objects_materials(G.main, id);
}
void assign_material(Object *ob, Material *ma, short act, int assign_type)
@ -924,7 +936,7 @@ void assign_material(Object *ob, Material *ma, short act, int assign_type)
if (ma)
id_us_plus(&ma->id);
test_object_materials(G.main, ob->data);
test_object_materials(ob, ob->data);
}

View File

@ -1010,7 +1010,7 @@ void BKE_mesh_assign_object(Object *ob, Mesh *me)
id_us_plus((ID *)me);
}
test_object_materials(G.main, (ID *)me);
test_object_materials(ob, (ID *)me);
test_object_modifiers(ob);
}
@ -2518,8 +2518,8 @@ Mesh *BKE_mesh_new_from_object(
BKE_mesh_tessface_ensure(tmpmesh);
}
/* make sure materials get updated in objects */
test_object_materials(bmain, &tmpmesh->id);
/* make sure materials get updated in object */
test_object_materials(tmpobj ? tmpobj : ob, &tmpmesh->id);
return tmpmesh;
}

View File

@ -540,7 +540,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
if (matmap) MEM_freeN(matmap);
/* other mesh users */
test_object_materials(bmain, (ID *)me);
test_all_objects_materials(bmain, (ID *)me);
/* free temp copy of destination shapekeys (if applicable) */
if (nkey) {

View File

@ -1564,7 +1564,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
ob_dst->data = obdata_id;
/* if amount of material indices changed: */
test_object_materials(bmain, ob_dst->data);
test_object_materials(ob_dst, ob_dst->data);
DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
break;

View File

@ -907,7 +907,7 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
material_index++;
} // loop over strokes
test_object_materials(freestyle_bmain, (ID *)mesh);
test_object_materials(object_mesh, (ID *)mesh);
#if 0 // XXX
BLI_assert(mesh->totvert == vertex_index);

View File

@ -227,7 +227,7 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char
id_us_min(&ob->id);
ob->data = data;
test_object_materials(bmain, ob->data);
test_object_materials(ob, ob->data);
return ob;
}

View File

@ -398,7 +398,7 @@ static void rna_Object_data_set(PointerRNA *ptr, PointerRNA value)
id_us_plus(id);
ob->data = id;
test_object_materials(G.main, id);
test_object_materials(ob, id);
if (GS(id->name) == ID_CU)
BKE_curve_type_test(ob);