I am working on an addon which bakes onto multiple meshes. Everything worked fine until I wanted to implement Ambient Occlusion baking.
To do this I need to hide all objects that have nothing to do with the bake from rendering.
Here is a pseudo code of what I am doing in the
for obj in bpy.data.objects: obj.hide_render = True obj.hide_viewport = False bpy.data.objects['high'].hide_render = False bpy.data.objects['high'].hide_viewport = False for obj in bpy.data.collections[context.scene.lowpoly_bake_obj].all_objects: bpy.data.objects['low'].hide_render = False # some setup work... bpy.data.objects['high'].select_set(True) bpy.context.view_layer.objects.active = bpy.data.objects['low'] # baking from active to selected... bpy.data.objects['low'].hide_render = True
Since I have introduced those
hide_viewport parts, Blender randomly crashes. But even after hours of debugging I just can't find the issue.
Here is the full source code if you want to try it out: https://github.com/flolu/blender-batch-baking/tree/0dc4bcfd17d57df49514fa6ed712e99015776c80
(especially this function here: https://github.com/flolu/blender-batch-baking/blob/0dc4bcfd17d57df49514fa6ed712e99015776c80/bake.py#L16)
As suggested by Robert Gützkow, I've now tried to build Blender from source to get a stack trace when it crashes:
Maybe this helps to find out what the actual problem is?
Here is an example file, which reliably crashes when you click the "Bake" button:
The addon can be installed from here: https://github.com/flolu/blender-batch-baking/tree/0dc4bcfd17d57df49514fa6ed712e99015776c80