Separating mesh parts breaks shape keys #71865

Closed
opened 2019-11-24 19:34:24 +01:00 by Takuya Sawatari · 8 comments

System Information
Operating system: Linux-5.0.0-36-generic-x86_64-with-debian-buster-sid 64 Bits
Graphics card: GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 430.50

Blender Version
Broken: version: 2.81 (sub 16), branch: master, commit date: 2019-11-20 14:27, hash: 26bd5ebd42
Worked: 2.80

Short description of error
Separating mesh parts to a new object breaks the original object's shape keys.

Exact steps for others to reproduce the error

  1. Create a UV sphere object.
  2. Enter edit mode.
  3. Duplicate the sphere mesh so that there are 4 spheres in the mesh object.
  4. Create a "Basis" shape key + one extra shape key "Key 1".
  5. Independently scale the middle 2 spheres a bit bigger in the "Key 1" shapekey.
  6. Select the mesh parts of the lower 2 spheres, press P and separate the selection.
  7. Enter object mode and select the old mesh object with the top 2 spheres.
  8. Enable the "Key 1" shapekey.
  9. Notice the incorrect deformation.

Test file:
blender_2_81_shape_key_bug4.blend

This also happens with complex project files which worked fine in Blender 2.80. Loading the test file in 2.80 and performing the procedure causes no issues.

**System Information** Operating system: Linux-5.0.0-36-generic-x86_64-with-debian-buster-sid 64 Bits Graphics card: GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 430.50 **Blender Version** Broken: version: 2.81 (sub 16), branch: master, commit date: 2019-11-20 14:27, hash: `26bd5ebd42` Worked: 2.80 **Short description of error** Separating mesh parts to a new object breaks the original object's shape keys. **Exact steps for others to reproduce the error** 1. Create a UV sphere object. 2. Enter edit mode. 3. Duplicate the sphere mesh so that there are 4 spheres in the mesh object. 4. Create a "Basis" shape key + one extra shape key "Key 1". 5. Independently scale the middle 2 spheres a bit bigger in the "Key 1" shapekey. 6. Select the mesh parts of the lower 2 spheres, press P and separate the selection. 7. Enter object mode and select the old mesh object with the top 2 spheres. 8. Enable the "Key 1" shapekey. 9. Notice the incorrect deformation. Test file: [blender_2_81_shape_key_bug4.blend](https://archive.blender.org/developer/F8162440/blender_2_81_shape_key_bug4.blend) This also happens with complex project files which worked fine in Blender 2.80. Loading the test file in 2.80 and performing the procedure causes no issues.

Added subscriber: @Takuya

Added subscriber: @Takuya
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Confirmed, checking...

Confirmed, checking...
Member

Added subscriber: @ideasman42

Added subscriber: @ideasman42
Member

This looks like it is caused by 79b703bb63.

@ideasman42 : mind checking?

This looks like it is caused by 79b703bb63. @ideasman42 : mind checking?
Campbell Barton self-assigned this 2019-11-25 11:52:29 +01:00

The error has been in Blender since 2.7x, probably going back much earlier.

While 79b703bb63 introduced a call to flush edits from edit-mode to object mode, saving the file will cause a flush too, so it's possible to reproduce the error in older releases too.

Although in my tests asan is reporting bad memory access and crashing (not just failing to update the shape keys).


Edit, this no longer crashes, however the issue remains with the shape-key not properly updating: 34902f2008


The following steps cause invalid memory access on a mesh with shape keys:

  • Create a new file containing a mesh with a shape key.
  • Enter edit mode.
  • Select half the mesh.
  • Separate the selection.
  • Save the file.
  • Exit edit-mode (invalid memory access).

While the crash can be fixed by checking the index range, there will still be an error updating shape-keys.

The problem is that the edit-meshes original indices aren't updated when flushing the changes back to the shape-key (when saving the file).
Existing edit-mode a second time tries to access indices from the original un-separated mesh and fails.


Here is a test that shows the error, run this with --factory-startup.

import bpy

bpy.ops.mesh.primitive_uv_sphere_add()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')

a = bpy.context.object
bpy.context.object.location.x += 2
bpy.ops.mesh.primitive_uv_sphere_add()
b = bpy.context.object
a.select_set(1)
b.select_set(1)
bpy.ops.object.join()

bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=False)
bpy.context.object.active_shape_key_index = 0


- -----------------------------
- Main setup done, now redo bug
#
- These lines can run in a loop.

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.separate(type='SELECTED')

#bpy.ops.wm.save_mainfile() # Also causes issue.
bpy.context.object.update_from_editmode()

bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.join()

The error has been in Blender since 2.7x, probably going back much earlier. While 79b703bb63 introduced a call to flush edits from edit-mode to object mode, saving the file will cause a flush too, so it's possible to reproduce the error in older releases too. Although in my tests asan is reporting bad memory access and crashing (not just failing to update the shape keys). ---- Edit, this no longer crashes, however the issue remains with the shape-key not properly updating: 34902f2008 ---- The following steps cause invalid memory access on a mesh with shape keys: - Create a new file containing a mesh with a shape key. - Enter edit mode. - Select half the mesh. - Separate the selection. - Save the file. - Exit edit-mode *(invalid memory access)*. While the crash can be fixed by checking the index range, there will still be an error updating shape-keys. The problem is that the edit-meshes original indices aren't updated when flushing the changes back to the shape-key (when saving the file). Existing edit-mode a second time tries to access indices from the original un-separated mesh and fails. ---- Here is a test that shows the error, run this with `--factory-startup`. ``` import bpy bpy.ops.mesh.primitive_uv_sphere_add() bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.object.mode_set(mode='OBJECT') a = bpy.context.object bpy.context.object.location.x += 2 bpy.ops.mesh.primitive_uv_sphere_add() b = bpy.context.object a.select_set(1) b.select_set(1) bpy.ops.object.join() bpy.ops.object.shape_key_add(from_mix=False) bpy.ops.object.shape_key_add(from_mix=False) bpy.context.object.active_shape_key_index = 0 - ----------------------------- - Main setup done, now redo bug # - These lines can run in a loop. bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.separate(type='SELECTED') #bpy.ops.wm.save_mainfile() # Also causes issue. bpy.context.object.update_from_editmode() bpy.ops.mesh.select_all(action='SELECT') bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.join() ```

This issue was referenced by 7711231838

This issue was referenced by 7711231838e726055c6690757f3799dff90bfd96

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
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
4 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#71865
No description provided.