Page MenuHome

closest_point_on_mesh() freezes Blender when called from a driver
Confirmed, NormalPublic

Description

System Information
Operating system: Windows-7-6.1.7601-SP1 64 Bits
Graphics card: GeForce GTX 580/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 391.35

Blender Version
Broken: version: 2.82 (sub 6), branch: master, commit date: 2020-01-07 16:11, hash: rB55daa0d44483
Worked: 2.79

Short description of error
Calling closest_point_on_mesh() from within a driver causes Blender to freeze.

Exact steps for others to reproduce the error


Open the file allowing scripts -> Freeze

Event Timeline

Richard Antalik (ISS) changed the task status from Needs Triage to Confirmed.Thu, Feb 6, 5:53 PM

Thread:

>	blender.exe!BPY_DECREF(void * pyob_ptr) Line 597	C
 	blender.exe!fcurve_free_driver(FCurve * fcu) Line 2110	C
 	blender.exe!free_fcurve(FCurve * fcu) Line 97	C
 	blender.exe!free_fcurves(ListBase * list) Line 119	C
 	blender.exe!BKE_animdata_free(ID * id, const bool do_id_user) Line 274	C
 	blender.exe!BKE_object_free(Object * ob) Line 513	C
 	blender.exe!DEG::deg_free_copy_on_write_datablock(ID * id_cow) Line 1065	C++
 	blender.exe!DEG::deg_update_copy_on_write_datablock(const DEG::Depsgraph * depsgraph, const DEG::IDNode * id_node) Line 944	C++
 	blender.exe!DEG::deg_evaluate_copy_on_write(Depsgraph * graph, const DEG::IDNode * id_node) Line 1080	C++
 	[Externí kód]	
 	[Vložený rámec] blender.exe!std::_Func_class<void,Depsgraph *>::operator()(Depsgraph * <_Args_0>) Line 969	C++
 	blender.exe!DEG::`anonymous namespace'::evaluate_node(const DEG::`anonymous-namespace'::DepsgraphEvalState * state, DEG::OperationNode * operation_node) Line 117	C++
 	blender.exe!DEG::`anonymous namespace'::deg_task_run_func(TaskPool * pool, void * taskdata, int thread_id) Line 129	C++
 	blender.exe!task_scheduler_thread_run(void * thread_p) Line 454	C
 	[Externí kód]

Main:

>	blender.exe!BLI_task_pool_work_and_wait(TaskPool * pool) Line 911	C
 	blender.exe!BLI_task_pool_work_wait_and_reset(TaskPool * pool) Line 970	C
 	blender.exe!DEG::deg_evaluate_on_refresh(DEG::Depsgraph * graph) Line 402	C++
 	blender.exe!DEG_evaluate_on_refresh(Main * bmain, Depsgraph * graph) Line 65	C++
 	blender.exe!scene_graph_update_tagged(Depsgraph * depsgraph, Main * bmain, bool only_if_tagged) Line 1358	C
 	blender.exe!CTX_data_ensure_evaluated_depsgraph(const bContext * C) Line 1393	C
 	blender.exe!eval_object_ensure(Object * ob, bContext * C, ReportList * reports, PointerRNA * rnaptr_depsgraph) Line 496	C
 	blender.exe!rna_Object_closest_point_on_mesh(Object * ob, bContext * C, ReportList * reports, float * origin, float distance, PointerRNA * rnaptr_depsgraph, bool * r_success, float * r_location, float * r_normal, int * r_index) Line 592	C
 	blender.exe!Object_closest_point_on_mesh_call(bContext * C, ReportList * reports, PointerRNA * _ptr, ParameterList * _parms) Line 3442	C
 	blender.exe!RNA_function_call(bContext * C, ReportList * reports, PointerRNA * ptr, FunctionRNA * func, ParameterList * parms) Line 7594	C
 	blender.exe!pyrna_func_call(BPy_FunctionRNA * self, _object * args, _object * kw) Line 6148	C
 	[Externí kód]	
 	blender.exe!BPY_driver_exec(PathResolvedRNA * anim_rna, ChannelDriver * driver, ChannelDriver * driver_orig, const float evaltime) Line 600	C
 	blender.exe!evaluate_driver(PathResolvedRNA * anim_rna, ChannelDriver * driver, ChannelDriver * driver_orig, const float evaltime) Line 2449	C
 	blender.exe!evaluate_fcurve_driver(PathResolvedRNA * anim_rna, FCurve * fcu, ChannelDriver * driver_orig, float evaltime) Line 3203	C
 	blender.exe!calculate_fcurve(PathResolvedRNA * anim_rna, FCurve * fcu, float evaltime) Line 3256	C
 	blender.exe!BKE_animsys_eval_driver(Depsgraph * depsgraph, ID * id, int driver_index, FCurve * fcu_orig) Line 4132	C
 	[Externí kód]	
 	[Vložený rámec] blender.exe!std::_Func_class<void,Depsgraph *>::operator()(Depsgraph * <_Args_0>) Line 969	C++
 	blender.exe!DEG::`anonymous namespace'::evaluate_node(const DEG::`anonymous-namespace'::DepsgraphEvalState * state, DEG::OperationNode * operation_node) Line 117	C++
 	blender.exe!DEG::`anonymous namespace'::deg_task_run_func(TaskPool * pool, void * taskdata, int thread_id) Line 129	C++
 	blender.exe!BLI_task_pool_work_and_wait(TaskPool * pool) Line 941	C
 	blender.exe!DEG::deg_evaluate_on_refresh(DEG::Depsgraph * graph) Line 404	C++
 	blender.exe!DEG_evaluate_on_refresh(Main * bmain, Depsgraph * graph) Line 65	C++
 	blender.exe!scene_graph_update_tagged(Depsgraph * depsgraph, Main * bmain, bool only_if_tagged) Line 1358	C
 	blender.exe!wm_event_do_depsgraph(bContext * C, bool is_after_open_file) Line 359	C
 	blender.exe!wm_file_read_post(bContext * C, const bool is_startup_file, const bool is_factory_startup, const bool use_data, const bool use_userdef, const bool reset_app_template) Line 557	C
 	blender.exe!WM_file_read(bContext * C, const unsigned char * filepath, ReportList * reports) Line 699	C
 	blender.exe!wm_revert_mainfile_exec(bContext * C, wmOperator * op) Line 2392	C
 	blender.exe!wm_operator_invoke(bContext * C, wmOperatorType * ot, wmEvent * event, PointerRNA * properties, ReportList * reports, const bool poll_only, bool use_last_properties) Line 1279	C
 	blender.exe!wm_operator_call_internal(bContext * C, wmOperatorType * ot, PointerRNA * properties, ReportList * reports, const short context, const bool poll_only, wmEvent * event) Line 1514	C
 	blender.exe!WM_operator_name_call_ptr(bContext * C, wmOperatorType * ot, short context, PointerRNA * properties) Line 1529	C
 	blender.exe!wm_block_autorun_warning_reload_with_scripts(bContext * C, void * arg_block, void * UNUSED_arg) Line 2782	C
 	blender.exe!ui_apply_but_funcs_after(bContext * C) Line 899	C
 	blender.exe!ui_popup_handler(bContext * C, const wmEvent * event, void * userdata) Line 10785	C
 	blender.exe!wm_handler_ui_call(bContext * C, wmEventHandler_UI * handler, const wmEvent * event, int always_pass) Line 620	C
 	blender.exe!wm_handlers_do_intern(bContext * C, wmEvent * event, ListBase * handlers) Line 2555	C
 	blender.exe!wm_handlers_do(bContext * C, wmEvent * event, ListBase * handlers) Line 2802	C
 	blender.exe!wm_event_do_handlers(bContext * C) Line 3181	C
 	blender.exe!WM_main(bContext * C) Line 421	C
 	blender.exe!main(int argc, const unsigned char * * UNUSED_argv_c) Line 520	C
 	[Externí kód]

This is a deadlock for the same reason as in T73516. The closest_point_on_mesh Python function requires an evaluated depsgraph, so you cannot use it in a driver which is evaluated during evaluation.
The deadlock happens because in your backtrace the main thead has the Python GIL and the other thread waits for it. Furthermore the main thread seems to be waiting on the other thread as well.

I tend to change the type of the report to Known Issue. In theory this could probably be solved, either by allowing the user to run closest_point_on_mesh on the original mesh or by only requiring a partially evaluated depsgraph. What do you think @Sergey Sharybin (sergey)?