Commit: 429771fed55119df4dfebcf1c8c3666f017fc0eb
Author: Bastien Montagne
Date:   Wed Nov 30 16:52:10 2022 +0100
Branches: master
https://developer.blender.org/rB429771fed55119df4dfebcf1c8c3666f017fc0eb

Add 'work around' to accessing data from volatile iterators in py API.

Re T102550.

===================================================================

M       doc/python_api/rst/info_gotcha.rst

===================================================================

diff --git a/doc/python_api/rst/info_gotcha.rst 
b/doc/python_api/rst/info_gotcha.rst
index 2dd6c3c92b1..e2a49898a4b 100644
--- a/doc/python_api/rst/info_gotcha.rst
+++ b/doc/python_api/rst/info_gotcha.rst
@@ -870,6 +870,26 @@ an issue but, due to internal implementation details, 
currently are:
   thus breaking any current iteration over ``Collection.all_objects``.
 
 
+.. rubric:: Do not:
+
+.. code-block:: python
+
+   # `all_objects` is an iterator. Using it directly while performing 
operations on its members that will update
+   # the memory accessed by the `all_objects` iterator will lead to invalid 
memory accesses and crashes.
+   for object in bpy.data.collections["Collection"].all_objects:
+        object.hide_viewport = True
+
+
+.. rubric:: Do:
+
+.. code-block:: python
+
+   # `all_objects[:]` is an independent list generated from the iterator. As 
long as no objects are deleted,
+   # its content will remain valid even if the data accessed by the 
`all_objects` iterator is modified.
+   for object in bpy.data.collections["Collection"].all_objects[:]:
+        object.hide_viewport = True
+
+
 sys.exit
 ========

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to