Fix memory leak when copying materials from evaluated data.
The materials array was being allocated even when `eval_totcol` is zero. The material code assumes that the array is nullptr when totcol is zero and would leak that memory. Only allocate the array when the material count is greater than zero.
This commit is contained in:
@@ -1234,7 +1234,7 @@ void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *
|
||||
|
||||
/* Create new material slots based on materials on evaluated geometry. */
|
||||
*orig_totcol = *eval_totcol;
|
||||
*orig_mat = MEM_cnew_array<Material *>(*eval_totcol, __func__);
|
||||
*orig_mat = *eval_totcol > 0 ? MEM_cnew_array<Material *>(*eval_totcol, __func__) : nullptr;
|
||||
for (int i = 0; i < *eval_totcol; i++) {
|
||||
Material *material_eval = (*eval_mat)[i];
|
||||
if (material_eval != nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user