Crash when joining objects in a loop #73700

Closed
opened 2020-02-09 23:56:40 +01:00 by Robert Guetzkow · 7 comments

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: 5314161491

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 #60491 which was closed because it couldn't be reproduced.

Exact steps for others to reproduce the error

  • Open the attached blend file
  • Run the script

crash_mwe.blend

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()
**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: `5314161491` **Short description of error** This problem was originally discovered by [Eduardo Ramírez ](https://blender.stackexchange.com/questions/166410/script-randomly-crashes-blender). 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 #60491 which was closed because it couldn't be reproduced. **Exact steps for others to reproduce the error** - Open the attached blend file - Run the script [crash_mwe.blend](https://archive.blender.org/developer/F8331656/crash_mwe.blend) ``` 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() ```
Author
Member

Added subscriber: @rjg

Added subscriber: @rjg
Author
Member

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]
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 changed title from Crash when joining in a loop to Crash when joining objects in a loop 2020-02-10 00:49:38 +01:00
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'
Campbell Barton self-assigned this 2020-02-11 06:15:50 +01:00

This is a known limitation in the Python API.

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

This is a known limitation in the Python API. See https://docs.blender.org/api/master/info_gotcha.html#removing-data
Author
Member

@ideasman42 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.

@ideasman42 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.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#73700
No description provided.