Regression: hide_set and hide_viewport on the same loop crash blender #102550
Labels
No Label
Meta
Good First Issue
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 & Devices
Module
Python API
Module
Rendering & Cycles
Module
Sculpt, Paint & Texture
Module
User Interface
Module
VFX & Video
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
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
8 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-manual#102550
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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@0190b104c8
Worked: 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_viewport
is 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_objects
list 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@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