Object modes are not loaded correctly in inactive scenes #91243

Closed
opened 2021-09-07 17:06:26 +02:00 by Falk David · 7 comments
Member

System Information
Operating system: Linux-5.11.0-7633-generic-x86_64-with-glibc2.33 64 Bits
Graphics card: NVIDIA GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 470.57.02

Blender Version
Broken: version: 3.0.0 Alpha, branch: master, commit date: 2021-09-07 08:18, hash: 8cc3d2d6f5
Broken: 2.93 LTS
Broken: 2.83 LTS
Worked: ?

Short description of error
When loading a .blend file with objects in another scene, the modes for these objects are not initialized correctly. The objects will be reset to object mode.
This affects all object types and all modes, except for (obviously) object mode and, interestingly, pose mode for armatures.

Exact steps for others to reproduce the error

  • Open Blender and create a full copy of the current scene.
  • Switch to the newly created scene, select the cube and go to e.g. sculpt mode.
  • Go back to the other scene, select the lamp, then save the file.
  • Reopen the file and go to the second scene.

The cube is in object mode, not sculpt mode.

If you save the file without selecting the lamp, the cube is in sculpt mode, but the toolsystem is not initialized (e.g. no cursor appears and the toolbar is empty). This also triggers and assert in debug builds.
BLI_assert failed: source/blender/windowmanager/intern/wm_toolsystem.c:86, WM_toolsystem_ref_from_context(), at 'tref == area->runtime.tool'

Investigation

I was digging into this issue because of this report: #89514. Here is what I found:
The core issue is happening in blender/source/blender/editors/util/ed_util.c:86 when ED_editors_init is called (from wm_file_read_post "updates to make after reading a file").
This function is supposed to enter the different modes for the objects. (Note that this is really important for multi-edit and multi-pose to work. All the objects need to be checked against the active object to also enter that mode.) Here is a summary of the structure of that function:

void ED_editors_init(bContext *C)
{
  ...
  Object *obact = CTX_data_active_object(C);
  for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
    int mode = ob->mode;
    if (mode == OB_MODE_OBJECT) {
      continue;
    }
    ...
    ob->mode = OB_MODE_OBJECT;
    if (obact && (ob->type == obact->type) && ...) {
       // Do the mode switching
    }
  }
  ...
}

The first issue seems to be that this loop iterates over all the objects (that are not in object mode) in the entire file. This is a problem, because we are comparing the mode of ob to obact which is the active object in the current scene. So this part of the code only really makes sense if obact is the active object in the scene that ob is also in.
Additionally we are overwriting the mode of that object ob and resetting it to object mode.

**System Information** Operating system: Linux-5.11.0-7633-generic-x86_64-with-glibc2.33 64 Bits Graphics card: NVIDIA GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 470.57.02 **Blender Version** Broken: version: 3.0.0 Alpha, branch: master, commit date: 2021-09-07 08:18, hash: `8cc3d2d6f5` Broken: 2.93 LTS Broken: 2.83 LTS Worked: ? **Short description of error** When loading a `.blend` file with objects in another scene, the modes for these objects are not initialized correctly. The objects will be reset to object mode. This affects *all* object types and all modes, *except* for (obviously) object mode and, interestingly, pose mode for armatures. **Exact steps for others to reproduce the error** - Open Blender and create a full copy of the current scene. - Switch to the newly created scene, select the cube and go to e.g. sculpt mode. - Go back to the other scene, **select the lamp**, then save the file. - Reopen the file and go to the second scene. # The cube is in object mode, not sculpt mode. If you save the file without selecting the lamp, the cube is in sculpt mode, but the toolsystem is not initialized (e.g. no cursor appears and the toolbar is empty). This also triggers and assert in debug builds. `BLI_assert failed: source/blender/windowmanager/intern/wm_toolsystem.c:86, WM_toolsystem_ref_from_context(), at 'tref == area->runtime.tool'` **Investigation** I was digging into this issue because of this report: #89514. Here is what I found: The core issue is happening in `blender/source/blender/editors/util/ed_util.c:86` when `ED_editors_init` is called (from `wm_file_read_post` "updates to make after reading a file"). This function is supposed to enter the different modes for the objects. (Note that this is really important for multi-edit and multi-pose to work. All the objects need to be checked against the active object to also enter that mode.) Here is a summary of the structure of that function: ``` void ED_editors_init(bContext *C) { ... Object *obact = CTX_data_active_object(C); for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { int mode = ob->mode; if (mode == OB_MODE_OBJECT) { continue; } ... ob->mode = OB_MODE_OBJECT; if (obact && (ob->type == obact->type) && ...) { // Do the mode switching } } ... } ``` The first issue seems to be that this loop iterates over all the objects (that are not in object mode) in the entire file. This is a problem, because we are comparing the mode of `ob` to `obact` which is the active object *in the current scene*. So this part of the code only really makes sense if `obact` is the active object in the scene that `ob` is also in. Additionally we are overwriting the mode of that object `ob` and resetting it to object mode.
Author
Member

Added subscriber: @filedescriptor

Added subscriber: @filedescriptor
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Added subscribers: @ideasman42, @brecht, @mont29

Added subscribers: @ideasman42, @brecht, @mont29

Wouldn't mind @ideasman42 or @brecht advice on this, but I would say always switching back objects in inactive scenes to Object mode is a decent compromise of safety/simplicity here... And then only do the mode switching if the object is in current active scene?

Otherwise in case some objects are instantiated in several scenes at the same time, correctly dealing with this can become fairly tricky and error prone am afraid.

Wouldn't mind @ideasman42 or @brecht advice on this, but I would say always switching back objects in inactive scenes to `Object` mode is a decent compromise of safety/simplicity here... And then only do the mode switching if the object is in current active scene? Otherwise in case some objects are instantiated in several scenes at the same time, correctly dealing with this can become fairly tricky and error prone am afraid.

It would be nice to preserve the modes in other scenes, but it seems complicated and I would not consider that a bug. Resetting to object mode seems reasonable to me.

It would be nice to preserve the modes in other scenes, but it seems complicated and I would not consider that a bug. Resetting to object mode seems reasonable to me.

This issue was referenced by dfb193f634

This issue was referenced by dfb193f634bf2d4b6a28b458d7d23b79bcd45633

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Bastien Montagne self-assigned this 2021-10-20 14:59:48 +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
5 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#91243
No description provided.