Page MenuHome

Cycles bake (bpy.ops.object.bake) unstable when using `uv_layer` parameter
Open, Needs TriagePublic

Description

Operating system: Ubuntu Linux 4.13.0-25-generic
Graphics card: none (Mesa using integrated i3-6100U)

Broken: 2.80, rBdf3e7d0361c6 2018-12-27 from thomas-schiex`s PPA
Calling bpy.ops.object.bake(uv_layer="UVMap") has unpredictable results and often crashes Blender. I discovered three issues, probably related:

  1. Start from the default file and just add an Image Texture to the default cube so that there is a Bake target.
  2. Execute bpy.ops.object.bake(uv_layer="UVMap") from the Python Console. The result is wrong.

OR

  1. Start from the default file and run this script from the Text editor:
import bpy
C = bpy.context
me = C.object.data
C.scene.render.engine = 'CYCLES'
image = bpy.data.images.new("Image", 100, 100, alpha=True)
for mat in me.materials:
    img = mat.node_tree.nodes.new('ShaderNodeTexImage')
    img.image = image
    mat.node_tree.nodes.active = img
tex = me.uv_layers.new(name="Tex 1")
C.object.update_from_editmode()
bpy.ops.object.bake(uv_layer=tex.name)
  1. Blender crashes. Backtrace usually shows Cycles ccl::triangle_point_normal, sometimes ccl::shader_setup_from_sample.

OR

  1. Start from the default file and run this code in the Text editor:
import bpy
C = bpy.context
sce = C.scene
me = C.object.data
sce.render.engine = 'CYCLES'
image = bpy.data.images.new("Image", 100, 100, alpha=True)
for mat in me.materials:
    img = mat.node_tree.nodes.new('ShaderNodeTexImage')
    img.image = image
    mat.node_tree.nodes.active = img
tex1 = me.uv_layers.new(name="Tex 1")
tex2 = me.uv_layers.new(name="Tex 2")

square = ((0, 0), (1, 0), (1, 1), (0, 1))
for face in me.polygons:
    for l, (x, y) in zip(face.loop_indices, square):
        tex1.data[l].uv = x * 0.5, y
        tex2.data[l].uv = x, y * 0.5
me.uv_layers.active = me.uv_layers[tex1.name]
C.object.update_from_editmode()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.mode_set(mode='OBJECT')
  1. Run this command in Python Console:
bpy.ops.object.bake(uv_layer="Tex 2")
  1. Blender crashes, same as above.

Details

Type
Bug