WIP: Fix #106127: crash enabling "Dynamic" on already bound MeshDeform mod #106617

Draft
Philipp Oeser wants to merge 1 commits from lichtwerk/blender:106127 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

The UI would already disable the prop, but setting via python or drivers
would still be possible, resulting in a crash because important dynamic
binding data would be missing in the modifier evaluation.

Now report an error in the modifier in such case instad of crashing.

Alternatively, re-binding under the hood could be investigated.

The UI would already disable the prop, but setting via python or drivers would still be possible, resulting in a crash because important dynamic binding data would be missing in the modifier evaluation. Now report an error in the modifier in such case instad of crashing. Alternatively, re-binding under the hood could be investigated.
Philipp Oeser added 1 commit 2023-04-06 10:38:21 +02:00
The UI would already disable the prop, but setting via python or drivers
would still be possible, resulting in a crash because important dynamic
binding data would be missing in the modifier evaluation.

Now report an error in the modifier in such case instad of crashing.

Alternatively, re-binding under the hood could be investigated.
Philipp Oeser added this to the Animation & Rigging project 2023-04-06 10:38:32 +02:00
Philipp Oeser added the
Interest
Modifiers
label 2023-04-06 10:38:52 +02:00
Philipp Oeser requested review from Sybren A. Stüvel 2023-04-06 10:39:04 +02:00
Philipp Oeser requested review from Sergey Sharybin 2023-04-06 10:39:13 +02:00
Sergey Sharybin reviewed 2023-04-06 11:17:58 +02:00
Sergey Sharybin left a comment
Owner

I wonder whether this should actually be handled on the RNA level and do BKE_report when the property is attempted to be assigned from Python?

Also, I am not sure whether the property is actually intended to be drivable/animatable.

But as a fall-back for older files this patch might still be useful.

Curios what you think about these points.

I wonder whether this should actually be handled on the RNA level and do `BKE_report` when the property is attempted to be assigned from Python? Also, I am not sure whether the property is actually intended to be drivable/animatable. But as a fall-back for older files this patch might still be useful. Curios what you think about these points.
@ -383,0 +383,4 @@
/* The UI will not allow enabling Dynamic once bound, but setting via RNA or drivers might
* happen. Evaluation will miss important binding data then though, so better do nothing in such
* case (alternatively re-binding could be considered, see above). */
if (mmd->flag & MOD_MDEF_DYNAMIC_BIND && !mmd->dynverts) {

Use parenthesis to avoid ambiguity:
if ((mmd->flag & MOD_MDEF_DYNAMIC_BIND) && !mmd->dynverts)

Use parenthesis to avoid ambiguity: `if ((mmd->flag & MOD_MDEF_DYNAMIC_BIND) && !mmd->dynverts)`

Alternatively, re-binding under the hood could be investigated.

I don't think this is a good idea. It'll make it too easy to accidentally discard people's data. Unless I'm mistaken, getting the binding data back once it's gone can be fairly tricky.

I wonder whether this should actually be handled on the RNA level and do BKE_report when the property is attempted to be assigned from Python?

Also, I am not sure whether the property is actually intended to be drivable/animatable.

I could see the use from an studio-customisation/automatisation point of view, where the driver determines which kind of binding is used in which situation. Unfortunately the bug reporter didn't mention their use case.

The desired behaviour I think also depends on the intent of this driver. If I'm right and it's indeed about automating what should happen when the 'Bind' button is pressed, it means that setting this property should not have any influence when the modifier is already bound.

The crash seems to occur because the property has two purposes now:

  1. determine which data is to be used when the modifier is evaluated, and
  2. determine which data is set when the binding operator is run.

I think a proper solution would be to disconnect those two purposes. It might be enough to alter meshdeform_vert_task() and replace if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) with if (mmd->dynverts != NULL). Or better:

const bool is_dynamic_bind = (mmd->dynverts != NULL);
if (is_dynamic_bind) { ... }

That way the 'binding mode' that was actually used to construct the data is used when evaluating, and this particular flag is only used for the binding operator.

> Alternatively, re-binding under the hood could be investigated. I don't think this is a good idea. It'll make it too easy to accidentally discard people's data. Unless I'm mistaken, getting the binding data back once it's gone can be fairly tricky. > I wonder whether this should actually be handled on the RNA level and do `BKE_report` when the property is attempted to be assigned from Python? > > Also, I am not sure whether the property is actually intended to be drivable/animatable. I could see the use from an studio-customisation/automatisation point of view, where the driver determines which kind of binding is used in which situation. Unfortunately the bug reporter didn't mention their use case. The desired behaviour I think also depends on the intent of this driver. If I'm right and it's indeed about automating what should happen when the 'Bind' button is pressed, it means that setting this property should not have any influence when the modifier is already bound. The crash seems to occur because the property has two purposes now: 1. determine which data is to be used when the modifier is evaluated, and 2. determine which data is set when the binding operator is run. I think a proper solution would be to disconnect those two purposes. It might be enough to alter `meshdeform_vert_task()` and replace `if (mmd->flag & MOD_MDEF_DYNAMIC_BIND)` with `if (mmd->dynverts != NULL)`. Or better: ```c const bool is_dynamic_bind = (mmd->dynverts != NULL); if (is_dynamic_bind) { ... } ``` That way the 'binding mode' that was actually used to construct the data is used when evaluating, and this particular flag is only used for the binding operator.
Author
Member

I would also assume the driver is set up to automate what should happen when binding is triggered.

It is not possible to have both binding data available (dynamic and "un-dynamic"), right? So if dynamic is available, it should always be used, so then what @dr.sybren suggests for meshdeform_vert_task makes sense. We could even hide the property completely from the UI after binding then?

Would still prefer if we additionally use BKE_modifier_set_error if data is not found (so the user knows something is missing/wrong)

I would also assume the driver is set up to automate what should happen when binding is triggered. It is not possible to have both binding data available (dynamic and "un-dynamic"), right? So if dynamic is available, it should always be used, so then what @dr.sybren suggests for `meshdeform_vert_task` makes sense. We could even hide the property completely from the UI after binding then? Would still prefer if we additionally use `BKE_modifier_set_error` if data is not found (so the user knows something is missing/wrong)

It is not possible to have both binding data available (dynamic and "un-dynamic"), right? So if dynamic is available, it should always be used

I think that's the case, yeah.

so then what @dr.sybren suggests for meshdeform_vert_task makes sense. We could even hide the property completely from the UI after binding then?

I think the property still holds value in the sense that it shows what kind of data was set.

Would still prefer if we additionally use BKE_modifier_set_error if data is not found (so the user knows something is missing/wrong)

👍

> It is not possible to have both binding data available (dynamic and "un-dynamic"), right? So if dynamic is available, it should always be used I think that's the case, yeah. > so then what @dr.sybren suggests for `meshdeform_vert_task` makes sense. We could even hide the property completely from the UI after binding then? I think the property still holds value in the sense that it shows what kind of data was set. > Would still prefer if we additionally use `BKE_modifier_set_error` if data is not found (so the user knows something is missing/wrong) :+1:
Philipp Oeser changed title from Fix #106127: crash enabling "Dynamic" on already bound MeshDeform mod to WIP: Fix #106127: crash enabling "Dynamic" on already bound MeshDeform mod 2023-04-24 09:56:43 +02:00
This pull request has changes conflicting with the target branch.
  • source/blender/modifiers/intern/MOD_meshdeform.c

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 106127:lichtwerk-106127
git checkout lichtwerk-106127
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 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#106617
No description provided.