Regression: hide_set and hide_viewport on the same loop crash blender
#102550
Closed
opened 3 months ago by JVM
·
25 comments
Labels
Apply labels
Clear labels
good first issue
legacy module/Animation & Rigging
legacy module/Core
legacy module/Development Management
legacy module/Eevee & Viewport
legacy module/Grease Pencil
legacy module/Modeling
legacy module/Nodes & Physics
legacy module/Pipeline, Assets & IO
legacy module/Platforms, Builds, Tests & Devices
legacy module/Python API
legacy module/Rendering & Cycles
legacy module/Sculpt, Paint & Texture
legacy module/User Interface
legacy module/VFX & Video
legacy project/2.81
legacy project/2.82
legacy project/2.83
legacy project/2.90
legacy project/2.91
legacy project/2.92
legacy project/2.93
legacy project/3.0
legacy project/3.1
legacy project/3.2
legacy project/3.3
legacy project/3.4
legacy project/3.5
legacy project/Animation & Rigging
legacy project/Asset Browser Project Overview
legacy project/Audio
legacy project/BF Blender: Next
legacy project/Compositing
legacy project/Core
legacy project/Cycles
legacy project/Datablocks and Libraries
legacy project/Development Management
legacy project/Documentation
legacy project/EEVEE & Viewport
legacy project/Game Engine
legacy project/Game Physics
legacy project/Geometry Nodes
legacy project/Good First Issue
legacy project/Grease Pencil
legacy project/Images & Movies
legacy project/Import/Export
legacy project/Infrastructure: Websites
legacy project/Line Art
legacy project/Modeling
legacy project/Modifiers
legacy project/Nodes
legacy project/Nodes & Physics
legacy project/Physics
legacy project/Pipeline, Assets & I/O
legacy project/Platform: Windows
legacy project/Python API
legacy project/Render & Cycles
legacy project/Sculpt, Paint & Texture
legacy project/Straightforward Issue
legacy project/Tracker Curfew
legacy project/Translations
legacy project/User Interface
legacy project/UV Editing
legacy project/VFX & Video
legacy project/Video Sequencer
Priority › High
Priority › Low
Priority › Normal
Status › Archived
Status › Confirmed
Status › Duplicate
Status › Needs Information from Developers
Status › Needs Information from User
Status › Needs Triage
Status › Resolved
straightforward issue
Type › Bug
Type › Design
Type › Known Issue
Type › Patch
Type › Report
Type › To Do
No Label
good first issue
legacy module/Animation & Rigging
legacy module/Core
legacy module/Development Management
legacy module/Eevee & Viewport
legacy module/Grease Pencil
legacy module/Modeling
legacy module/Nodes & Physics
legacy module/Pipeline, Assets & IO
legacy module/Platforms, Builds, Tests & Devices
legacy module/Python API
legacy module/Rendering & Cycles
legacy module/Sculpt, Paint & Texture
legacy module/User Interface
legacy module/VFX & Video
legacy project/2.81
legacy project/2.82
legacy project/2.83
legacy project/2.90
legacy project/2.91
legacy project/2.92
legacy project/2.93
legacy project/3.0
legacy project/3.1
legacy project/3.2
legacy project/3.3
legacy project/3.4
legacy project/3.5
legacy project/Animation & Rigging
legacy project/Asset Browser Project Overview
legacy project/Audio
legacy project/BF Blender: Next
legacy project/Compositing
legacy project/Core
legacy project/Cycles
legacy project/Datablocks and Libraries
legacy project/Development Management
legacy project/Documentation
legacy project/EEVEE & Viewport
legacy project/Game Engine
legacy project/Game Physics
legacy project/Geometry Nodes
legacy project/Good First Issue
legacy project/Grease Pencil
legacy project/Images & Movies
legacy project/Import/Export
legacy project/Infrastructure: Websites
legacy project/Line Art
legacy project/Modeling
legacy project/Modifiers
legacy project/Nodes
legacy project/Nodes & Physics
legacy project/Physics
legacy project/Pipeline, Assets & I/O
legacy project/Platform: Windows
legacy project/Python API
legacy project/Render & Cycles
legacy project/Sculpt, Paint & Texture
legacy project/Straightforward Issue
legacy project/Tracker Curfew
legacy project/Translations
legacy project/User Interface
legacy project/UV Editing
legacy project/VFX & Video
legacy project/Video Sequencer
Priority › High
Priority › Low
Priority › Normal
Status › Archived
Status › Confirmed
Status › Duplicate
Status › Needs Information from Developers
Status › Needs Information from User
Status › Needs Triage
Status › Resolved
straightforward issue
Type › Bug
Type › Design
Type › Known Issue
Type › Patch
Type › Report
Type › To Do
Milestone
Set milestone
Clear milestone
No items
No Milestone
Projects
Set Project
Clear projects
No project
Assignees
Assign users
Clear assignees
No Assignees
8 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/documentation#102550
Reference in new issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
No
Yes
System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3090/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 516.59
Blender Version
Broken: version: 3.4.0 Beta, branch: master, commit date: 2022-11-14 01:01, hash:
blender/blender@0190b104c8Worked: blender-3.4.0-alpha+master.788f3d72cf89-windows.amd64-release
Caused by blender/blender@09b9e1e95e
Short description of error
When you try to access to hide_set and hide_viewport properties of objects inside a collection inside the same for loop, blender crashes
Exact steps for others to reproduce the error
1- Open the provided test file
2- Look at the text editor script, there´s 2 for loops and on both of them, there´re lines commented
3-If you execute the script, everything goes ok, objects will be hided on both methods, but it´s redundant to make it in two different loops
4-CTRL +Z to undo or revert the file
5-Now uncomment in any of the loops the line commented, in order to execute the two operations at once on the same for loop
6-Blender crashes
hide_set_and_viewport_bug.blend
Added subscriber: @JVM
blender/blender#103611 was marked as duplicate of this issue
Added subscriber: @deadpin
Due to how Collections are implemented, setting certain fields like
hide_viewportis problematic. This particular case is so surprising we had to specifically document it a few years back: https://docs.blender.org/api/master/info_gotcha.html#unfortunate-corner-casesCreate a copy of the
.all_objectslist and use the copy for iteration.Mmm i see.
Workaround is always good, but still a bug anyway @deadpin
Yeah, I filed the original blender/blender#62406 bug
Thanks buddy :)
Added subscriber: @lichtwerk
@deadpin: but is it expected to crash? @JVM also mentioned it didnt crash in blender/blender@788f3d72cf
Ah. If it started working that is news to me and it would be great to solve actually :) I didn't fight the original bug's closure way back when but as far as I knew it's been crashy since the beginning.
Changed status from 'Needs Triage' to: 'Confirmed'
Crash indeed seems like a regression, will check on this...
Added subscriber: @Sergey
Caused by blender/blender@09b9e1e95e
@Sergey: I am aware of https://docs.blender.org/api/master/info_gotcha.html#unfortunate-corner-cases, but crash is a regression, mind checking?
hide_set and hide_viewport on the same loop crash blenderto Regression: hide_set and hide_viewport on the same loop crash blender 3 months ago@lichtwerk In both cases (before and after my change) this is a heap-use-after-free issue: P3317: (An Untitled Masterwork)
Is just the change exposed the wrong memory access which has already been happening before.
Perhaps something like
all_objects = bpy.data.collections["TEST"].all_objects- [x]; for object in all_objects: ...will lead to the desired result.And i am not really sure if or how we can prevent crash when the content of collection changes in the loop. Also, don't really see this mentioned in the corner cases page.
Thx checking
Yep, this indeed has no issues (should have tried that myself)
"breaking any current iteration over Collection.all_objects" is something that is happening here (just not clear that this includes crashes)
So maybe we can put the above workaround in the documentation and call this done?
Somehow I've managed to miss that sentence yesterday.
I think that could be good.
Added subscriber: @monique
Had a quick look at this issue. Here are my findings:
The hide_set syncs the viewlayer when it's flagged out-of-sync and tags the viewlayer out of sync at the end because the base->flag (HIDDEN) has been modified
The hide_viewport flags the viewlayer out of sync and frees all caches (basically it calls for a full remap: BKE_main_collection_sync_remap ).
So in the loop, when hide_set tries to sync I suspect that the iterator is pointing to unallocated memory, because of the full syncing in hide_viewport.
It is unclear to me how the iterator "gets updated" when caches/memory get freed during the full sync.
Added subscriber: @Blendify
@Blendify : could you add that? ^^
Added subscriber: @mont29
Will update the doc. Note that using
- [x]syntax is enough, no need to explicitly store the list copy:for object in bpy.data.collections["TEST"].all_objects[:]:Changed status from 'Confirmed' to: 'Archived'
Added subscriber: @reed2000