Skip to content

Commit db6cbce

Browse files
committed
Fix crash when texture bake cannot access evaluated mesh data
Baking could fail to access an objects evaluated mesh data (see #107426), while the error remains, prefer an error instead of crashing. Since the depsgraph runs Python callbacks I don't think we can provide a guarantee the mesh data will available, so even if #107426 is fixed, it's reasonable to have a check here.
1 parent 932fa1b commit db6cbce

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

source/blender/editors/object/object_bake_api.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,24 @@ static int bake(const BakeAPIRender *bkr,
15811581
BASE_ENABLED_RENDER);
15821582
highpoly[i].mesh = BKE_mesh_new_from_object(nullptr, highpoly[i].ob_eval, false, false);
15831583

1584+
/* NOTE(@ideasman42): While ideally this should never happen,
1585+
* it's possible the `visibility_flag` assignment in this function
1586+
* is overridden by animated visibility, see: #107426.
1587+
*
1588+
* There is also the potential that scripts called from depsgraph callbacks
1589+
* change this value too, so we can't guarantee the mesh will be available.
1590+
* Use an error here instead of a warning so users don't accidentally perform
1591+
* a bake which seems to succeed with invalid results.
1592+
* If visibility could be forced/overridden - it would help avoid the problem. */
1593+
if (UNLIKELY(highpoly[i].mesh == nullptr)) {
1594+
BKE_reportf(
1595+
reports,
1596+
RPT_ERROR,
1597+
"Failed to access mesh from object \"%s\", ensure it's visible while rendering",
1598+
ob_iter->id.name + 2);
1599+
goto cleanup;
1600+
}
1601+
15841602
/* Low-poly to high-poly transformation matrix. */
15851603
copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->object_to_world().ptr());
15861604
invert_m4_m4(highpoly[i].imat, highpoly[i].obmat);

0 commit comments

Comments
 (0)