Page MenuHome

Crash on interating over "all_objects".
Closed, ArchivedPublic

Description

System Information
Operating system: Windows-10-10.0.19044-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 511.65

Blender Version
Broken: version: 3.0.0, branch: master, commit date: 2021-12-02 18:35, hash: rBf1cca3055776

Short description of error
Running a for loop over anyCollection.all_objects results in a crash.

Exact steps for others to reproduce the error

  • Open .blend file
  • Run the script

Event Timeline

Richard Antalik (ISS) changed the task status from Needs Triage to Confirmed.Mar 15 2022, 10:48 PM

Trace:

>	blender.exe!rna_Collection_all_objects_get(CollectionPropertyIterator * iter) Line 64	C
 	blender.exe!Collection_all_objects_get(CollectionPropertyIterator * iter) Line 188	C
 	blender.exe!Collection_all_objects_next(CollectionPropertyIterator * iter) Line 210	C
 	blender.exe!RNA_property_collection_next(CollectionPropertyIterator * iter) Line 3678	C
 	blender.exe!pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA * self) Line 7123	C
 	python310_d.dll!_PyEval_EvalFrameDefault(_ts * tstate, _frame * f, int throwflag) Line 4002	C
 	[Inline Frame] python310_d.dll!_PyEval_EvalFrame(_ts *) Line 46	C
 	python310_d.dll!_PyEval_Vector(_ts * tstate, PyFrameConstructor * con, _object * locals, _object * const * args, unsigned __int64 argcount, _object * kwnames) Line 5072	C
 	python310_d.dll!PyEval_EvalCode(_object * co, _object * globals, _object * locals) Line 1135	C
 	blender.exe!python_script_exec(bContext * C, const unsigned char * fn, Text * text, ReportList * reports, const bool do_jump) Line 122	C
 	blender.exe!BPY_run_text(bContext * C, Text * text, ReportList * reports, const bool do_jump) Line 218	C
 	blender.exe!text_run_script(bContext * C, ReportList * reports) Line 773	C
 	blender.exe!text_run_script_exec(bContext * C, wmOperator * op) Line 814	C
 	blender.exe!wm_operator_invoke(bContext * C, wmOperatorType * ot, const wmEvent * event, PointerRNA * properties, ReportList * reports, const bool poll_only, bool use_last_properties) Line 1379	C
 	blender.exe!wm_operator_call_internal(bContext * C, wmOperatorType * ot, PointerRNA * properties, ReportList * reports, const wmOperatorCallContext context, const bool poll_only, const wmEvent * event) Line 1572	C
 	blender.exe!WM_operator_name_call_ptr(bContext * C, wmOperatorType * ot, wmOperatorCallContext context, PointerRNA * properties, const wmEvent * event) Line 1621	C
 	blender.exe!WM_operator_name_call_ptr_with_depends_on_cursor(bContext * C, wmOperatorType * ot, wmOperatorCallContext opcontext, PointerRNA * properties, const wmEvent * event, const unsigned char * drawstr) Line 1813	C
 	blender.exe!ui_apply_but_funcs_after(bContext * C) Line 1012	C
 	blender.exe!ui_handler_region_menu(bContext * C, const wmEvent * event, void * UNUSED_userdata) Line 11390	C
 	blender.exe!wm_handler_ui_call(bContext * C, wmEventHandler_UI * handler, const wmEvent * event, int always_pass) Line 732	C
 	blender.exe!wm_handlers_do_intern(bContext * C, wmWindow * win, wmEvent * event, ListBase * handlers) Line 3076	C
 	blender.exe!wm_handlers_do(bContext * C, wmEvent * event, ListBase * handlers) Line 3195	C
 	blender.exe!wm_event_do_handlers(bContext * C) Line 3763	C
 	blender.exe!WM_main(bContext * C) Line 626	C
 	blender.exe!main(int argc, const unsigned char * * UNUSED_argv_c) Line 548	C
 	[External Code]

This is, unfortunately, a documented problem: https://docs.blender.org/api/master/info_gotcha.html#unfortunate-corner-cases

Modifying the hide_viewport or hide_render properties on an object will re-construct the collection object list. As such you are enumerating over a list that might change which isn't permitted.

Make a copy of the all_objects collection and iterate over that instead

the_copy = [o for o in bpy.data.collections["HOST"].all_objects]
for obj in the_copy:
    hideObj(obj, 0)

That said, unsure if the crash can be avoided. A python enumeration error should still surface though.

Thanks for clarifying. I ended up copying the objects into a dictionary and I get neither crash nor python error.

Richard Antalik (ISS) closed this task as Archived.Mar 16 2022, 11:33 PM

Did not know this is documented. I think making copy should be safe-ish, since crash seems to be caused due to incorrect iterator state.

In any case since this is documented limitation, will close this, as there is no bug.