Fix T50714: Collections: Adding object to scene without an existing collection

This was causing blender to segfault.

We now add create a new collection and link to the layer before adding
the new object

(also included unittests, and requires updated lib/tests)
This commit is contained in:
Dalai Felinto
2017-02-23 12:35:14 +01:00
parent 8261a84ffb
commit 2f9a0dfe64
7 changed files with 164 additions and 1 deletions

View File

@@ -309,3 +309,30 @@ class RenderLayerTesting(unittest.TestCase):
),
"Scene dump files differ")
def do_object_add_no_collection(self, add_mode):
"""
Test for adding objects when no collection
exists in render layer
"""
import bpy
# empty layer of collections
layer = bpy.context.render_layer
while layer.collections:
layer.collections.unlink(layer.collections[0])
# add new objects
if add_mode == 'EMPTY':
bpy.ops.object.add() # 'Empty'
elif add_mode == 'CYLINDER':
bpy.ops.mesh.primitive_cylinder_add() # 'Cylinder'
elif add_mode == 'TORUS':
bpy.ops.mesh.primitive_torus_add() # 'Torus'
self.assertEqual(len(layer.collections), 1, "New collection not created")
collection = layer.collections[0]
self.assertEqual(len(collection.objects), 1, "New collection is empty")