Crash after manipulating Object.hide_viewport while iterating Collection.all_objects #62406

Closed
opened 2019-03-10 02:09:42 +01:00 by Jesse Yurkovich · 11 comments

System Information
Operating system: Win10
Graphics card: nVidia 1070

Blender Version
Broken: 2.80 (sub 47), branch: master, commit date: 2019-03-09 16:19, hash: 4041249943
Worked: A February build was fine, but I don't know the hash :-/

Short description of error
Running this script fragment will cause a crash inside the Collection.all_objects code path -- one of the 2 hide_viewport lines seems to trigger it:

import bpy

for obj in bpy.context.collection.all_objects:
    print('Processing object : ', obj.name)

    prev_hide_viewport = obj.hide_viewport
    obj.hide_viewport = False

    obj.select_set(False)
    obj.hide_viewport = prev_hide_viewport

Exact steps for others to reproduce the error
hide_viewport-crash.blend

  • Load attached .blend
  • Hit Run Script
Exception thrown: read access violation.
base was 0xFFFFFFFFFFFFFFDF.

blender.exe!rna_Collection_all_objects_get(CollectionPropertyIterator * iter) Line 62	C
blender.exe!Collection_all_objects_get(CollectionPropertyIterator * iter) Line 160	C
blender.exe!Collection_all_objects_next(CollectionPropertyIterator * iter) Line 181	C
blender.exe!RNA_property_collection_next(CollectionPropertyIterator * iter) Line 3660	C
blender.exe!pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA * self) Line 6634	C
python37_d.dll!00007ff80ec4b9ac()	Unknown
python37_d.dll!00007ff80ec49ecc()	Unknown
python37_d.dll!00007ff80ec48726()	Unknown
python37_d.dll!00007ff80ec4867e()	Unknown
blender.exe!python_script_exec(bContext * C, const unsigned char * fn, Text * text, ReportList * reports, const bool do_jump) Line 469	C

**System Information** Operating system: Win10 Graphics card: nVidia 1070 **Blender Version** Broken: 2.80 (sub 47), branch: master, commit date: 2019-03-09 16:19, hash: 40412499433e Worked: A February build was fine, but I don't know the hash :-/ **Short description of error** Running this script fragment will cause a crash inside the Collection.all_objects code path -- one of the 2 hide_viewport lines seems to trigger it: ``` import bpy for obj in bpy.context.collection.all_objects: print('Processing object : ', obj.name) prev_hide_viewport = obj.hide_viewport obj.hide_viewport = False obj.select_set(False) obj.hide_viewport = prev_hide_viewport ``` **Exact steps for others to reproduce the error** [hide_viewport-crash.blend](https://archive.blender.org/developer/F6792584/hide_viewport-crash.blend) - Load attached .blend - Hit Run Script ``` Exception thrown: read access violation. base was 0xFFFFFFFFFFFFFFDF. blender.exe!rna_Collection_all_objects_get(CollectionPropertyIterator * iter) Line 62 C blender.exe!Collection_all_objects_get(CollectionPropertyIterator * iter) Line 160 C blender.exe!Collection_all_objects_next(CollectionPropertyIterator * iter) Line 181 C blender.exe!RNA_property_collection_next(CollectionPropertyIterator * iter) Line 3660 C blender.exe!pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA * self) Line 6634 C python37_d.dll!00007ff80ec4b9ac() Unknown python37_d.dll!00007ff80ec49ecc() Unknown python37_d.dll!00007ff80ec48726() Unknown python37_d.dll!00007ff80ec4867e() Unknown blender.exe!python_script_exec(bContext * C, const unsigned char * fn, Text * text, ReportList * reports, const bool do_jump) Line 469 C ```
Author
Member

Added subscriber: @deadpin

Added subscriber: @deadpin

#89576 was marked as duplicate of this issue

#89576 was marked as duplicate of this issue

Added subscribers: @mont29, @ZedDB

Added subscribers: @mont29, @ZedDB
Bastien Montagne was assigned by Sebastian Parborg 2019-03-11 12:30:06 +01:00

Backtrace:

Thread 1 "blender" received signal SIGSEGV, Segmentation fault.
0x00005555583e46df in rna_ID_refine (ptr=0x7fffffffcd00) at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_ID.c:300
300		return ID_code_to_RNA_type(GS(id->name));
(gdb) bt
- 0  0x00005555583e46df in rna_ID_refine (ptr=0x7fffffffcd00) at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_ID.c:300
- 1  0x00005555583cca2e in rna_pointer_inherit_refine (ptr=0x7fffce3b6630, type=0x55555d952f00 <RNA_Object>, data=0x300000005)
    at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_access.c:208
#2  0x00005555584145e5 in rna_Collection_all_objects_get (iter=0x7fffce3b6630)
    at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_collection.c:62
#3  0x0000555558415097 in Collection_all_objects_get (iter=0x7fffce3b6630)
    at /home/zed/programmering/blender_master/blender/build/source/blender/makesrna/intern/rna_collection_gen.c:162
#4  0x00005555584151cd in Collection_all_objects_next (iter=0x7fffce3b6630)
    at /home/zed/programmering/blender_master/blender/build/source/blender/makesrna/intern/rna_collection_gen.c:183
#5  0x00005555583d6cba in RNA_property_collection_next (iter=0x7fffce3b6630)
    at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_access.c:3659
#6  0x0000555557959c28 in pyrna_prop_collection_iter_next (self=0x7fffce3b6620)
    at /home/zed/programmering/blender_master/blender/source/blender/python/intern/bpy_rna.c:6632
- 7  0x00007ffff75cda72 in _PyEval_EvalFrameDefault () from /usr/lib64/libpython3.7m.so.1.0
- 8  0x00007ffff769f872 in _PyEval_EvalCodeWithName () from /usr/lib64/libpython3.7m.so.1.0
- 9  0x00007ffff769fae2 in PyEval_EvalCodeEx () from /usr/lib64/libpython3.7m.so.1.0
- 10 0x00007ffff769fb0b in PyEval_EvalCode () from /usr/lib64/libpython3.7m.so.1.0
#11 0x000055555794a7b8 in python_script_exec (C=0x7fffea058188, fn=0x0, text=0x7fffcf5f8408, reports=0x7fffcf556b88, do_jump=true)
    at /home/zed/programmering/blender_master/blender/source/blender/python/intern/bpy_interface.c:469
#12 0x000055555794aacf in BPY_execute_text (C=0x7fffea058188, text=0x7fffcf5f8408, reports=0x7fffcf556b88, do_jump=true)
    at /home/zed/programmering/blender_master/blender/source/blender/python/intern/bpy_interface.c:562
#13 0x00005555573556bf in text_run_script (C=0x7fffea058188, reports=0x7fffcf556b88)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/space_text/text_ops.c:599
#14 0x0000555557355794 in text_run_script_exec (C=0x7fffea058188, op=0x7fffe9719ec8)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/space_text/text_ops.c:637
#15 0x0000555557223cce in wm_operator_invoke (C=0x7fffea058188, ot=0x7fffe4e8b7c8, event=0x7fffd8479a08, properties=0x7fffffffd6f0, reports=0x0,
    poll_only=false, use_last_properties=true) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1353
#16 0x000055555722436b in wm_operator_call_internal (C=0x7fffea058188, ot=0x7fffe4e8b7c8, properties=0x7fffffffd6f0, reports=0x0, context=1, poll_only=false,
    event=0x7fffd8479a08) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1550
#17 0x000055555722458e in WM_operator_name_call_ptr (C=0x7fffea058188, ot=0x7fffe4e8b7c8, context=1, properties=0x7fffffffd6f0)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1598
#18 0x0000555557567743 in ui_apply_but_funcs_after (C=0x7fffea058188)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/interface/interface_handlers.c:770
#19 0x0000555557580593 in ui_handler_region_menu (C=0x7fffea058188, event=0x7fffcb954e88, UNUSED_userdata=0x7fffcf16a188)
    at /home/zed/programmering/blender_master/blender/source/blender/editors/interface/interface_handlers.c:9903
#20 0x0000555557221956 in wm_handler_ui_call (C=0x7fffea058188, handler=0x7fffceca0e88, event=0x7fffcb954e88, always_pass=0)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:585
#21 0x0000555557226a90 in wm_handlers_do_intern (C=0x7fffea058188, event=0x7fffcb954e88, handlers=0x7fffcf16b498)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:2491
#22 0x0000555557227467 in wm_handlers_do (C=0x7fffea058188, event=0x7fffcb954e88, handlers=0x7fffcf16b498)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:2720
#23 0x000055555722869b in wm_event_do_handlers (C=0x7fffea058188)
    at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:3071
- 24 0x000055555721cebf in WM_main (C=0x7fffea058188) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm.c:418
- 25 0x00005555572175f4 in main (argc=1, argv=0x7fffffffdd28) at /home/zed/programmering/blender_master/blender/source/creator/creator.c:505

@mont29 feel free to reassign if this is not for you.

Backtrace: ``` Thread 1 "blender" received signal SIGSEGV, Segmentation fault. 0x00005555583e46df in rna_ID_refine (ptr=0x7fffffffcd00) at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_ID.c:300 300 return ID_code_to_RNA_type(GS(id->name)); (gdb) bt - 0 0x00005555583e46df in rna_ID_refine (ptr=0x7fffffffcd00) at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_ID.c:300 - 1 0x00005555583cca2e in rna_pointer_inherit_refine (ptr=0x7fffce3b6630, type=0x55555d952f00 <RNA_Object>, data=0x300000005) at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_access.c:208 #2 0x00005555584145e5 in rna_Collection_all_objects_get (iter=0x7fffce3b6630) at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_collection.c:62 #3 0x0000555558415097 in Collection_all_objects_get (iter=0x7fffce3b6630) at /home/zed/programmering/blender_master/blender/build/source/blender/makesrna/intern/rna_collection_gen.c:162 #4 0x00005555584151cd in Collection_all_objects_next (iter=0x7fffce3b6630) at /home/zed/programmering/blender_master/blender/build/source/blender/makesrna/intern/rna_collection_gen.c:183 #5 0x00005555583d6cba in RNA_property_collection_next (iter=0x7fffce3b6630) at /home/zed/programmering/blender_master/blender/source/blender/makesrna/intern/rna_access.c:3659 #6 0x0000555557959c28 in pyrna_prop_collection_iter_next (self=0x7fffce3b6620) at /home/zed/programmering/blender_master/blender/source/blender/python/intern/bpy_rna.c:6632 - 7 0x00007ffff75cda72 in _PyEval_EvalFrameDefault () from /usr/lib64/libpython3.7m.so.1.0 - 8 0x00007ffff769f872 in _PyEval_EvalCodeWithName () from /usr/lib64/libpython3.7m.so.1.0 - 9 0x00007ffff769fae2 in PyEval_EvalCodeEx () from /usr/lib64/libpython3.7m.so.1.0 - 10 0x00007ffff769fb0b in PyEval_EvalCode () from /usr/lib64/libpython3.7m.so.1.0 #11 0x000055555794a7b8 in python_script_exec (C=0x7fffea058188, fn=0x0, text=0x7fffcf5f8408, reports=0x7fffcf556b88, do_jump=true) at /home/zed/programmering/blender_master/blender/source/blender/python/intern/bpy_interface.c:469 #12 0x000055555794aacf in BPY_execute_text (C=0x7fffea058188, text=0x7fffcf5f8408, reports=0x7fffcf556b88, do_jump=true) at /home/zed/programmering/blender_master/blender/source/blender/python/intern/bpy_interface.c:562 #13 0x00005555573556bf in text_run_script (C=0x7fffea058188, reports=0x7fffcf556b88) at /home/zed/programmering/blender_master/blender/source/blender/editors/space_text/text_ops.c:599 #14 0x0000555557355794 in text_run_script_exec (C=0x7fffea058188, op=0x7fffe9719ec8) at /home/zed/programmering/blender_master/blender/source/blender/editors/space_text/text_ops.c:637 #15 0x0000555557223cce in wm_operator_invoke (C=0x7fffea058188, ot=0x7fffe4e8b7c8, event=0x7fffd8479a08, properties=0x7fffffffd6f0, reports=0x0, poll_only=false, use_last_properties=true) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1353 #16 0x000055555722436b in wm_operator_call_internal (C=0x7fffea058188, ot=0x7fffe4e8b7c8, properties=0x7fffffffd6f0, reports=0x0, context=1, poll_only=false, event=0x7fffd8479a08) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1550 #17 0x000055555722458e in WM_operator_name_call_ptr (C=0x7fffea058188, ot=0x7fffe4e8b7c8, context=1, properties=0x7fffffffd6f0) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:1598 #18 0x0000555557567743 in ui_apply_but_funcs_after (C=0x7fffea058188) at /home/zed/programmering/blender_master/blender/source/blender/editors/interface/interface_handlers.c:770 #19 0x0000555557580593 in ui_handler_region_menu (C=0x7fffea058188, event=0x7fffcb954e88, UNUSED_userdata=0x7fffcf16a188) at /home/zed/programmering/blender_master/blender/source/blender/editors/interface/interface_handlers.c:9903 #20 0x0000555557221956 in wm_handler_ui_call (C=0x7fffea058188, handler=0x7fffceca0e88, event=0x7fffcb954e88, always_pass=0) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:585 #21 0x0000555557226a90 in wm_handlers_do_intern (C=0x7fffea058188, event=0x7fffcb954e88, handlers=0x7fffcf16b498) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:2491 #22 0x0000555557227467 in wm_handlers_do (C=0x7fffea058188, event=0x7fffcb954e88, handlers=0x7fffcf16b498) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:2720 #23 0x000055555722869b in wm_event_do_handlers (C=0x7fffea058188) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm_event_system.c:3071 - 24 0x000055555721cebf in WM_main (C=0x7fffea058188) at /home/zed/programmering/blender_master/blender/source/blender/windowmanager/intern/wm.c:418 - 25 0x00005555572175f4 in main (argc=1, argv=0x7fffffffdd28) at /home/zed/programmering/blender_master/blender/source/creator/creator.c:505 ``` @mont29 feel free to reassign if this is not for you.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

This is expected actually… though rather unfortunates. Here is what happens:

  • looping over collection.all_objects uses a temp internal cache.
  • Setting object.hide_viewport calls BKE_main_collection_sync_remap() has part of its update process.
  • That BKE_main_collection_sync_remap() function invalidates all cahces of all collections, including the one we are looping on.
  • Hence the crash…

As usual, you should avoid iterating over data when modifying data, you never know when you will end up re-allocating things and hence accessing bad memory, this works instead:

import bpy

ob_names = [ob.name for ob in bpy.context.collection.all_objects]
for ob_name in ob_names:

print('Processing object : ', ob_name)
obj = bpy.data.objects[ob_name]

prev_hide_viewport = obj.hide_viewport
obj.hide_viewport = False


obj.select_set(False)
obj.hide_viewport = prev_hide_viewport

Note that this is not really considered as a nice behavior, and some enhancements/refinements are possible here, but this is not a bug either. Thanks for the report anyway.

This is expected actually… though rather unfortunates. Here is what happens: * looping over `collection.all_objects` uses a temp internal cache. * Setting `object.hide_viewport` calls `BKE_main_collection_sync_remap()` has part of its update process. * That `BKE_main_collection_sync_remap()` function invalidates all cahces of all collections, including the one we are looping on. * Hence the crash… As usual, you should avoid iterating over data when modifying data, you never know when you will end up re-allocating things and hence accessing bad memory, this works instead: ```lang=python import bpy ob_names = [ob.name for ob in bpy.context.collection.all_objects] for ob_name in ob_names: ``` print('Processing object : ', ob_name) obj = bpy.data.objects[ob_name] prev_hide_viewport = obj.hide_viewport obj.hide_viewport = False ``` ``` obj.select_set(False) obj.hide_viewport = prev_hide_viewport ``` ``` Note that this is not really considered as a nice behavior, and some enhancements/refinements are possible here, but this is not a bug either. Thanks for the report anyway.
Author
Member

Aaahhhh such a minefield :) Thanks for looking and spending time on this; I'll have to modify several of my scripts to account for this... I only thought modifying the collection itself, not items within it, would be bad -- but I guess there's a hidden manipulation here.

Can this be added to https://docs.blender.org/api/blender2.8/info_gotcha.html -- Namely "Even modifying items within certain collections (even if the collection itself does not change) should be avoided" as I can't find it there.

Aaahhhh such a minefield :) Thanks for looking and spending time on this; I'll have to modify several of my scripts to account for this... I only thought modifying the collection itself, not items within it, would be bad -- but I guess there's a hidden manipulation here. Can this be added to https://docs.blender.org/api/blender2.8/info_gotcha.html -- Namely "Even modifying items within certain collections (even if the collection itself does not change) should be avoided" as I can't find it there.

Done, thanks (will appear on next API doc rebuild).

Done, thanks (will appear on next API doc rebuild).
Member

Added subscribers: @barakooda, @PratikPB2123, @lichtwerk

Added subscribers: @barakooda, @PratikPB2123, @lichtwerk
Member

Added subscriber: @kursadk

Added subscriber: @kursadk
Member

It will be probably very helpful to include example working code from @mont29 in https://docs.blender.org/api/blender2.8/info_gotcha.html

It will be probably very helpful to include example working code from @mont29 in https://docs.blender.org/api/blender2.8/info_gotcha.html
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
6 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#62406
No description provided.