When running jobs in a background thread (e.g. baking), we usually have lock the user interface to avoid race conditions when the UI is drawn or is interacted with.
The way we do this right now is not ideal for two main reasons:
- There are multiple flags which control this locking and it’s often unclear what they do exactly. In practice some code just uses all of the the flags just to be sure. There are
ARegionType::do_lock
,WindowManagerRuntime::is_interface_locked
andG.is_rendering
(which is often used by baking code too). - Taking the locking into account is opt-in. This leads to code having race conditions that are very hard to find. The drawing code of some editors may be thread-safe in vanilla Blender, but is not if there are additional panels defined in Python.
I don’t have the final solution yet, but it would be great if we could achieve the following:
- Have a more well defined set of UI locks with clear definitions of what they mean and imply.
- Be more explicit about what drawing code is allowed to run while some background job modifies data. We need to be especially careful with all places that may allow Python code.
Might also be worth investigating communicating between the background job and UI/main thread so that the background job can tell the UI thread when it’s safe to redraw and then waits until the redraw is done before continuing.
Before I can continue figuring out what the right solution is, I need some feedback: What is the user expected to be allowed to see and do while baking and while rendering?
For context, I was looking into this because incomplete locking seems to be the cause for #132941 - Regression: Geometry Nodes: At some point the Point Cloud simulation disappears - blender - Blender Projects.