LayerCollection: Invalid operation on main data from within depsgraph-controlled update code. #112534

Closed
opened 2023-09-18 17:49:01 +02:00 by Bastien Montagne · 4 comments

System Information
Operating system: N/A
Graphics card: N/A

Blender Version
Broken: Current main
Worked: ???

Short description of error
The move to deferred synchronization of LayerCollections (with underlying Collection hierarchy) seems to have created an unexpected issue with the ViewLayer depsgraph-update code. Essentially, this code should be called from main thread only (for orig data), not worker threads.

The issue is even more critical when a custom depsgraph is used from within a worker thread, which happens e.g. with USD exporter (but also rendering I think).

Exact steps for others to reproduce the error
Here is a backtrace leading to a fatal CLOG and crash. I got it by trying to export in USD a scene from the pets project (040_0050.anim.blend from r3055, but pretty sure this issue will appear randomly with any complex enough file):

./bin/blender() ./source/creator/creator.cc:196: callback_clg_fatal(void*) (0xf3c2740)
./bin/blender() ./intern/clog/clog.c:374: clg_ctx_fatal_action (0x1d201748)
./bin/blender() ./intern/clog/clog.c:546: CLG_logf (0x1d2032e9)
./bin/blender() ./source/blender/blenkernel/intern/layer.cc:1250 (discriminator 4): view_layer_objects_base_cache_validate(ViewLayer*, LayerCollection*) (0x106b2b72)
./bin/blender() ./source/blender/blenkernel/intern/layer.cc:1263 (discriminator 1): view_layer_objects_base_cache_validate(ViewLayer*, LayerCollection*) (0x106b2c5e)
./bin/blender() ./source/blender/blenkernel/intern/layer.cc:1263 (discriminator 1): view_layer_objects_base_cache_validate(ViewLayer*, LayerCollection*) (0x106b2c5e)
./bin/blender() ./source/blender/blenkernel/intern/layer.cc:1392: BKE_layer_collection_sync (0x106b4435)
./bin/blender() ./source/blender/blenkernel/intern/layer.cc:991: BKE_view_layer_synced_ensure (0x106af32c)
./bin/blender() ./source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc:98: blender::deg::DepsgraphNodeBuilder::build_view_layer(Scene*, ViewLayer*, blender::deg::eDepsNode_LinkedState_Type) (0x14a0401c)
./bin/blender() ./source/blender/depsgraph/intern/builder/pipeline_view_layer.cc:21: blender::deg::ViewLayerBuilderPipeline::build_nodes(blender::deg::DepsgraphNodeBuilder&) (0x14ad7e3d)
./bin/blender() ./source/blender/depsgraph/intern/builder/pipeline.cc:58: blender::deg::AbstractBuilderPipeline::build_step_nodes() (0x14ac886f)
./bin/blender() ./source/blender/depsgraph/intern/builder/pipeline.cc:37: blender::deg::AbstractBuilderPipeline::build() (0x14ac787c)
./bin/blender() ./source/blender/depsgraph/intern/depsgraph_build.cc:235: DEG_graph_build_from_view_layer (0x14b90694)
./bin/blender() ./source/blender/io/usd/intern/usd_capi_export.cc:323: blender::io::usd::export_startjob(void*, bool*, bool*, float*) (0x17a88bf4)
./bin/blender() ./source/blender/windowmanager/intern/wm_jobs.cc:388: do_job_thread(void*) (0x13c5fcf9)
./bin/blender() ./source/blender/blenlib/intern/threads.cc:178: tslot_thread_start(void*) (0x13b4025a)

Am not entirely sure what is the best approach here (assuming own analysis of the issue above is correct). I would not expect though that depsgraph building (or evaluating) code has to ensure its orig data is valid and up-to-date? So we likely need some function to ensure that this kind of deferred update of orig data is done before starting depsgraph building?

**System Information** Operating system: N/A Graphics card: N/A **Blender Version** Broken: Current main Worked: ??? **Short description of error** The move to deferred synchronization of LayerCollections (with underlying Collection hierarchy) seems to have created an unexpected issue with the ViewLayer depsgraph-update code. Essentially, this code should be called from main thread only (for orig data), not worker threads. The issue is even more critical when a custom depsgraph is used from within a worker thread, which happens e.g. with USD exporter (but also rendering I think). **Exact steps for others to reproduce the error** Here is a backtrace leading to a fatal CLOG and crash. I got it by trying to export in USD a scene from the pets project (`040_0050.anim.blend` from `r3055`, but pretty sure this issue will appear randomly with any complex enough file): ``` ./bin/blender() ./source/creator/creator.cc:196: callback_clg_fatal(void*) (0xf3c2740) ./bin/blender() ./intern/clog/clog.c:374: clg_ctx_fatal_action (0x1d201748) ./bin/blender() ./intern/clog/clog.c:546: CLG_logf (0x1d2032e9) ./bin/blender() ./source/blender/blenkernel/intern/layer.cc:1250 (discriminator 4): view_layer_objects_base_cache_validate(ViewLayer*, LayerCollection*) (0x106b2b72) ./bin/blender() ./source/blender/blenkernel/intern/layer.cc:1263 (discriminator 1): view_layer_objects_base_cache_validate(ViewLayer*, LayerCollection*) (0x106b2c5e) ./bin/blender() ./source/blender/blenkernel/intern/layer.cc:1263 (discriminator 1): view_layer_objects_base_cache_validate(ViewLayer*, LayerCollection*) (0x106b2c5e) ./bin/blender() ./source/blender/blenkernel/intern/layer.cc:1392: BKE_layer_collection_sync (0x106b4435) ./bin/blender() ./source/blender/blenkernel/intern/layer.cc:991: BKE_view_layer_synced_ensure (0x106af32c) ./bin/blender() ./source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc:98: blender::deg::DepsgraphNodeBuilder::build_view_layer(Scene*, ViewLayer*, blender::deg::eDepsNode_LinkedState_Type) (0x14a0401c) ./bin/blender() ./source/blender/depsgraph/intern/builder/pipeline_view_layer.cc:21: blender::deg::ViewLayerBuilderPipeline::build_nodes(blender::deg::DepsgraphNodeBuilder&) (0x14ad7e3d) ./bin/blender() ./source/blender/depsgraph/intern/builder/pipeline.cc:58: blender::deg::AbstractBuilderPipeline::build_step_nodes() (0x14ac886f) ./bin/blender() ./source/blender/depsgraph/intern/builder/pipeline.cc:37: blender::deg::AbstractBuilderPipeline::build() (0x14ac787c) ./bin/blender() ./source/blender/depsgraph/intern/depsgraph_build.cc:235: DEG_graph_build_from_view_layer (0x14b90694) ./bin/blender() ./source/blender/io/usd/intern/usd_capi_export.cc:323: blender::io::usd::export_startjob(void*, bool*, bool*, float*) (0x17a88bf4) ./bin/blender() ./source/blender/windowmanager/intern/wm_jobs.cc:388: do_job_thread(void*) (0x13c5fcf9) ./bin/blender() ./source/blender/blenlib/intern/threads.cc:178: tslot_thread_start(void*) (0x13b4025a) ``` ------------------------ Am not entirely sure what is the best approach here (assuming own analysis of the issue above is correct). I would not expect though that depsgraph building (or evaluating) code has to ensure its orig data is valid and up-to-date? So we likely need some function to ensure that this kind of deferred update of orig data is done before starting depsgraph building?
Author
Owner
CC @dr.sybren @Sergey @JacquesLucke

Building of the dependency graph currently should happen from either within a main thread, or the interface is to be locked. The latter is how the render job creates the depsgraph. You can see example of it in the engine_render_view_layer.

Evaluation is a bit more tricky story. Currently we have prefetch jobs which evaluates depsgraph at different scenes, but modification of scene re-starts the job, so conflict never really happens. The only step of evaluation which has to happen while the original data is still intact is the initial "copy-on-write", after that evaluation of the graph at different frames should be possible. What we are missing, however, is some thread-safety when user makes edits: currently tagging iterates over all depsgraphs and tags things. If some thread is evaluating scene at the same time a problem will happen.

Building of the dependency graph currently should happen from either within a main thread, or the interface is to be locked. The latter is how the render job creates the depsgraph. You can see example of it in the `engine_render_view_layer`. Evaluation is a bit more tricky story. Currently we have prefetch jobs which evaluates depsgraph at different scenes, but modification of scene re-starts the job, so conflict never really happens. The only step of evaluation which has to happen while the original data is still intact is the initial "copy-on-write", after that evaluation of the graph at different frames should be possible. What we are missing, however, is some thread-safety when user makes edits: currently tagging iterates over all depsgraphs and tags things. If some thread is evaluating scene at the same time a problem will happen.

Building of the dependency graph currently should happen from either within a main thread, or the interface is to be locked. The latter is how the render job creates the depsgraph. You can see example of it in the engine_render_view_layer.

This might be good to document in the DEG_graph_build_… functions.

The USD exporter does lock the interface, so that alone might actually not be enough to avoid this issue. For the USD exporter it's rather trivial to move the code that builds the depsgraph to the main thread, though.

> Building of the dependency graph currently should happen from either within a main thread, or the interface is to be locked. The latter is how the render job creates the depsgraph. You can see example of it in the `engine_render_view_layer`. This might be good to document in the `DEG_graph_build_…` functions. The USD exporter does lock the interface, so that alone might actually not be enough to avoid this issue. For the USD exporter it's rather trivial to move the code that builds the depsgraph to the main thread, though.
Author
Owner

This was fixed by commit 5cf3654d9d

This was fixed by commit 5cf3654d9d
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-10-18 16:09:42 +02:00
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
3 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#112534
No description provided.