fix [#34125] Crash when bake margin = 0
[blender.git] / source / blender / render / intern / source / bake.c
index 665361e..f304ca5 100644 (file)
@@ -1072,12 +1072,14 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
                                if (!ibuf)
                                        continue;
 
-                               userdata = (BakeImBufuserData *) ibuf->userdata;
-                               RE_bake_ibuf_filter(ibuf, userdata->mask_buffer, re->r.bake_filter);
+                               if (userdata) {
+                                       userdata = (BakeImBufuserData *) ibuf->userdata;
+                                       RE_bake_ibuf_filter(ibuf, userdata->mask_buffer, re->r.bake_filter);
 
-                               if (use_displacement_buffer) {
-                                       RE_bake_ibuf_normalize_displacement(ibuf, userdata->displacement_buffer, userdata->mask_buffer,
-                                                                           displacement_min, displacement_max);
+                                       if (use_displacement_buffer) {
+                                               RE_bake_ibuf_normalize_displacement(ibuf, userdata->displacement_buffer, userdata->mask_buffer,
+                                                                                   displacement_min, displacement_max);
+                                       }
                                }
 
                                ibuf->userflags |= IB_BITMAPDIRTY;