user_remap fails silently when object is in edit mode #110232

Open
opened 2023-07-18 08:05:29 +02:00 by Andrej · 5 comments
Contributor

Blender 3.6

Way to reproduce:

  1. Create new empty blender project
  2. Select cube
  3. Enter edit mode
  4. Run the code below

Results - mesh wasn't replaced and no errors occured. Expected - to either mesh to change or get some warning/error.

import bmesh
import bpy

obj = bpy.context.active_object

data = bpy.data.meshes.new('test')
bm = bmesh.new()
bmesh.ops.create_monkey(bm)
bm.to_mesh(data)
bm.free()

obj.data.user_remap(data)
assert obj.data == data
Blender 3.6 Way to reproduce: 1) Create new empty blender project 2) Select cube 3) Enter edit mode 4) Run the code below Results - mesh wasn't replaced and no errors occured. Expected - to either mesh to change or get some warning/error. ```python import bmesh import bpy obj = bpy.context.active_object data = bpy.data.meshes.new('test') bm = bmesh.new() bmesh.ops.create_monkey(bm) bm.to_mesh(data) bm.free() obj.data.user_remap(data) assert obj.data == data ```
Andrej added the
Type
Report
Status
Needs Triage
Priority
Normal
labels 2023-07-18 08:05:29 +02:00
Member

The mesh will not replace in edit mode, it will only do in object mode, but I do agree there needs to be a warning message of some kind, otherwise it can be confusing.

in foreach_libblock_remap_callback():

/* Special hack in case it's Object->data and we are in edit mode, and new_id is not NULL
   * (otherwise, we follow common NEVER_NULL flags).
   * (skipped_indirect too). */
  if ((violates_never_null && skip_never_null) ||
      (is_obj_editmode && (((Object *)id_owner)->data == *id_p) &&
       (expected_mapping_result == ID_REMAP_RESULT_SOURCE_REMAPPED)) ||
      (skip_indirect && is_indirect) || (is_reference && skip_reference))
  {
    foreach_libblock_remap_callback_skip(id_owner,
                                         id_p,
                                         cb_flag,
                                         is_indirect,
                                         is_reference,
                                         violates_never_null,
                                         is_obj,
                                         is_obj_editmode);
  }

It does have a debug message print tho, but it's only enabled when compiler flag DEBUG_PRINT is defined. I guess we can improve it by printing it in the python console when called from bpy API? cc @Jeroen-Bakker

The mesh will not replace in edit mode, it will only do in object mode, but I do agree there needs to be a warning message of some kind, otherwise it can be confusing. in `foreach_libblock_remap_callback()`: ``` /* Special hack in case it's Object->data and we are in edit mode, and new_id is not NULL * (otherwise, we follow common NEVER_NULL flags). * (skipped_indirect too). */ if ((violates_never_null && skip_never_null) || (is_obj_editmode && (((Object *)id_owner)->data == *id_p) && (expected_mapping_result == ID_REMAP_RESULT_SOURCE_REMAPPED)) || (skip_indirect && is_indirect) || (is_reference && skip_reference)) { foreach_libblock_remap_callback_skip(id_owner, id_p, cb_flag, is_indirect, is_reference, violates_never_null, is_obj, is_obj_editmode); } ``` It does have a debug message print tho, but it's only enabled when compiler flag `DEBUG_PRINT` is defined. I guess we can improve it by printing it in the python console when called from bpy API? cc @Jeroen-Bakker
YimingWu added
Module
Python API
Status
Confirmed
and removed
Status
Needs Triage
labels 2023-07-18 10:05:55 +02:00
YimingWu changed title from user_remap fails silently in edit mode to `user_remap` fails silently when object is in edit mode 2023-07-18 10:12:27 +02:00
Author
Contributor

But shouldn't it raise an Exception, not just a warning though? If user_remap practically doesn't work in EDIT mode.

But shouldn't it raise an Exception, not just a warning though? If `user_remap` practically doesn't work in EDIT mode.
Member

It technically already have the mechanism for printing out such info, so I guess it's easier to have a warning/info message.

Also it's not that user_remap doesn't work in Edit mode, because it will still remap other objects and IDs, it's only "skipping" the current editing mesh to avoid breaking the state. It might be possible to let the operator exit existing edit mode mesh objects, and do the remapping, then edit again, but this will not work in multi-edit, and there are other situations that user_remap will skip too, so I'm not sure there are any better ways than current logic...

It technically _already have_ the mechanism for printing out such info, so I guess it's easier to have a warning/info message. Also it's not that `user_remap` doesn't work in Edit mode, because it will still remap other objects and IDs, it's only "skipping" the current editing mesh to avoid breaking the state. It might be possible to let the operator exit existing edit mode mesh objects, and do the remapping, then edit again, but this will not work in multi-edit, and there are other situations that `user_remap` will skip too, so I'm not sure there are any better ways than current logic...
Author
Contributor

I mean if in ID1.user_remap(ID2) ID1 or ID2 is edit mesh shouldn't it throw an error because it wouldn't work and you'd be able to figure it only by debugging the consequences of user_remap not working in this case?

It might be possible to let the operator exit existing edit mode mesh objects, and do the remapping, then edit again

sounds scary, not sure if exiting edit mode for remap wouldn't create some other issues😁

I mean if in `ID1.user_remap(ID2)` `ID1` or `ID2` is edit mesh shouldn't it throw an error because it wouldn't work and you'd be able to figure it only by debugging the consequences of `user_remap` not working in this case? > It might be possible to let the operator exit existing edit mode mesh objects, and do the remapping, then edit again sounds scary, not sure if exiting edit mode for remap wouldn't create some other issues😁
Philipp Oeser added
Module
Core
Interest
Python API
Interest
ID Management
and removed
Module
Python API
labels 2023-08-21 14:37:08 +02:00
Author
Contributor

If someone met the same issue and trying to work around it, then

  • need to make sure mesh.is_editmode is False before doing mesh.user_remap otherwise it wouldn't work. Checking object.mode != "EDIT" could be insufficient since it could be that object in OBJECT mode when mesh is still in EDIT.
  • in mesh.user_remap(mesh1) the status of mesh1.is_editmode doesn't matter, it'll work either way.
If someone met the same issue and trying to work around it, then - need to make sure `mesh.is_editmode` is `False` before doing `mesh.user_remap` otherwise it wouldn't work. Checking `object.mode != "EDIT"` could be insufficient since it could be that object in OBJECT mode when mesh is still in EDIT. - in `mesh.user_remap(mesh1)` the status of `mesh1.is_editmode` doesn't matter, it'll work either way.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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
2 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#110232
No description provided.