Maniphest T73700

Crash when joining objects in a loop
Closed, ArchivedBUG

Assigned To
Campbell Barton (campbellbarton)
Authored By
Robert Guetzkow (rjg)
Feb 9 2020, 11:56 PM
Tags
  • BF Blender
Subscribers
Campbell Barton (campbellbarton)
Robert Guetzkow (rjg)

Description

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 436.30

Blender Version
Broken: version: 2.83 (sub 2), branch: master, commit date: 2020-02-09 16:59, hash: rB5314161491d4

Short description of error

This problem was originally discovered by Eduardo Ramírez.

Joining objects while iterating over a collection of objects, e.g. bpy.context.view_layer.objects or bpy.context.scene.objects, results in a crash.

It's possible that this isn't supposed to work, since the collection that is being iterated over is modified inside the loop, which is rarely a good thing. This issue is similar to T60491 which was closed because it couldn't be reproduced.

Exact steps for others to reproduce the error

  1. Open the attached blend file
  2. Run the script

import bpy


for obj in bpy.context.view_layer.objects:
    bpy.ops.object.select_all(action='SELECT')
    bpy.context.view_layer.objects.active = obj
    bpy.ops.object.join()

Event Timeline

Robert Guetzkow (rjg) created this task.Feb 9 2020, 11:56 PM
Robert Guetzkow (rjg) added a comment.Feb 9 2020, 11:59 PM

The crash occurs in the loop when the next element is accessed.

pyrna_struct_CreatePyObject(PointerRNA * ptr) Line 7264	C
pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA * self) Line 6955	C
[External Code]
Robert Guetzkow (rjg) updated the task description.Feb 10 2020, 12:00 AM
Robert Guetzkow (rjg) renamed this task from Crash when joining in a loop to Crash when joining objects in a loop.Feb 10 2020, 12:49 AM
Robert Guetzkow (rjg) changed the task status from Needs Triage to Confirmed.Feb 10 2020, 9:49 AM
Robert Guetzkow (rjg) updated the task description.
Aaron Carlisle (Blendify) changed the subtype of this task from "Report" to "Bug".Feb 10 2020, 9:15 PM
Campbell Barton (campbellbarton) closed this task as Archived.Feb 11 2020, 6:15 AM
Campbell Barton (campbellbarton) claimed this task.
Campbell Barton (campbellbarton) added a subscriber: Campbell Barton (campbellbarton).

This is a known limitation in the Python API.

See https://docs.blender.org/api/master/info_gotcha.html#removing-data

Robert Guetzkow (rjg) added a comment.Feb 11 2020, 10:15 AM

@Campbell Barton (campbellbarton) Thank you for confirming that this is a known limitation. I wasn't sure if the gotcha applies to implicit removal through operators and if there were any safe-guards implemented for that case. Modifying an iterable while iterating over it is not a good idea anyway.