Fix T53638: View layer renaming crashes 2/2
authorDalai Felinto <dfelinto@gmail.com>
Wed, 27 Dec 2017 15:32:30 +0000 (13:32 -0200)
committerDalai Felinto <dfelinto@gmail.com>
Wed, 27 Dec 2017 15:39:28 +0000 (13:39 -0200)
This fixes renaming the view layer via Python.

This bug was introduced originally in 3a95bdfc65d. Although I suspect it was
around for longer, since this commit didn't touch this part of the code.

But basically we need the id of the RNA property to be the one that owns
the data (view layer).

source/blender/makesrna/intern/rna_context.c
tests/python/view_layer/CMakeLists.txt
tests/python/view_layer/test_view_layer_rename.py [new file with mode: 0644]

index 3df114282fd40d7fe6041a345d143ec2f523992e..bcd805b0f3a693d67dba5ed9aef07b170cd1aa87 100644 (file)
@@ -132,7 +132,11 @@ static PointerRNA rna_Context_scene_get(PointerRNA *ptr)
 static PointerRNA rna_Context_view_layer_get(PointerRNA *ptr)
 {
        bContext *C = (bContext *)ptr->data;
-       return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, CTX_data_view_layer(C));
+       Scene *scene = CTX_data_scene(C);
+       PointerRNA scene_ptr;
+
+       RNA_id_pointer_create(&scene->id, &scene_ptr);
+       return rna_pointer_inherit_refine(&scene_ptr, &RNA_ViewLayer, CTX_data_view_layer(C));
 }
 
 static PointerRNA rna_Context_view_render_get(PointerRNA *ptr)
index 22cfcd344f32df49fda9cf01cf110deb0acdd674..1c0648afead798fcc6e10430a7cc5861e4715932 100644 (file)
@@ -178,3 +178,4 @@ VIEW_LAYER_TEST(scene_copy_e)
 VIEW_LAYER_TEST(scene_copy_f)
 VIEW_LAYER_TEST(scene_delete)
 VIEW_LAYER_TEST(scene_write_read)
+VIEW_LAYER_TEST(view_layer_rename)
diff --git a/tests/python/view_layer/test_view_layer_rename.py b/tests/python/view_layer/test_view_layer_rename.py
new file mode 100644 (file)
index 0000000..fefb317
--- /dev/null
@@ -0,0 +1,33 @@
+# ############################################################
+# Importing - Same For All Render Layer Tests
+# ############################################################
+
+import unittest
+import os
+import sys
+
+from view_layer_common import *
+
+
+# ############################################################
+# Testing
+# ############################################################
+
+class UnitTesting(ViewLayerTesting):
+    def test_view_layer_rename(self):
+        """
+        See if we can rename view layers.
+        """
+        import bpy
+        view_layer = bpy.context.view_layer
+        print("View layer name: " + view_layer.name)
+        view_layer.name = "New Name"
+
+
+# ############################################################
+# Main - Same For All Render Layer Tests
+# ############################################################
+
+if __name__ == '__main__':
+    UnitTesting._extra_arguments = setup_extra_arguments(__file__)
+    unittest.main()