Fix: Various issues with auto smooth versioning #119539

Merged
Hans Goudey merged 15 commits from HooglyBoogly/blender:fix-auto-smooth-versioning into blender-v4.1-release 2024-03-18 20:15:45 +01:00
Member

This PR fixes several issues with the versioning that replaces the old
auto smooth flag with a modifier.

One issue is that the flag wasn't cleared in the initial versioning
code. That means some objects have the replacement modifier but their
meshes still have the flag set. The fix for that is to make the
versioning idempotent by trying to find an existing node group before
adding a new one. The versionig is now re-run on all objects to clear
the flags. Flags on all meshes are cleared too, even unused meshes.
That could cause loss of the auto-smooth when the mesh is linked from
a different blend-file, but that situation should be very rare.

Another issue was that the versioning wasn't run when linking objects.
That was simple to solve by adding the versioning where the proxy
versioning already existed for that case.

Finally, arguably the largest issue was that the the newly added node
groups were always added as local data-blocks. When linking, having
library data-blocks point to local data-blocks not in that library is
quite bad and breaks assumptions around Blender. This is solved by
having an auto smooth node group per library.

Resolves #119516, #119455, #119447

This PR fixes several issues with the versioning that replaces the old auto smooth flag with a modifier. One issue is that the flag wasn't cleared in the initial versioning code. That means some objects have the replacement modifier but their meshes still have the flag set. The fix for that is to make the versioning idempotent by trying to find an existing node group before adding a new one. The versionig is now re-run on all objects to clear the flags. Flags on all meshes are cleared too, even unused meshes. That could cause loss of the auto-smooth when the mesh is linked from a different blend-file, but that situation should be very rare. Another issue was that the versioning wasn't run when linking objects. That was simple to solve by adding the versioning where the proxy versioning already existed for that case. Finally, arguably the largest issue was that the the newly added node groups were always added as local data-blocks. When linking, having library data-blocks point to local data-blocks not in that library is quite bad and breaks assumptions around Blender. This is solved by having an auto smooth node group per library. Resolves #119516, #119455, #119447
Hans Goudey added 1 commit 2024-03-15 21:07:29 +01:00
Hans Goudey added this to the 4.1 milestone 2024-03-15 21:07:49 +01:00
Hans Goudey added 4 commits 2024-03-18 17:02:41 +01:00
Hans Goudey added 1 commit 2024-03-18 17:40:31 +01:00
Hans Goudey changed title from WIP: Fix: Various issues with auto smooth versioning to Fix: Various issues with auto smooth versioning 2024-03-18 17:54:01 +01:00
Hans Goudey added 2 commits 2024-03-18 18:00:31 +01:00
Hans Goudey requested review from Brecht Van Lommel 2024-03-18 18:05:09 +01:00
Hans Goudey requested review from Jacques Lucke 2024-03-18 18:05:09 +01:00
Jacques Lucke reviewed 2024-03-18 18:19:50 +01:00
@ -2244,0 +2256,4 @@
return result;
}
static bool is_auto_smooth_node_tree(const bNodeTree &group)
Member

Would be good to mention the function name that builds the node group we compare against here.

Would be good to mention the function name that builds the node group we compare against here.
HooglyBoogly marked this conversation as resolved
@ -2247,2 +2335,3 @@
BKE_modifier_unique_name(&object.modifiers, &md->modifier);
md->node_group = get_node_group();
md->node_group = get_node_group(object.id.lib);
md->node_group->id.us++;
Member

Any reason for using direct increment/decrement instead of the corresponding utility methods? (id_us_plus)

Any reason for using direct increment/decrement instead of the corresponding utility methods? (`id_us_plus`)
Author
Member

Hmm, no, I'll use those

Hmm, no, I'll use those
HooglyBoogly marked this conversation as resolved
@ -2268,3 +2357,4 @@
using namespace blender;
using namespace blender::bke;
/* Add the node group lazily and share it among all objects in the main database. */
Member

This comment seems outdated.

This comment seems outdated.
HooglyBoogly marked this conversation as resolved
@ -2276,0 +2378,4 @@
/* Remove the default user. The count is tracked manually when assigning to modifiers. */
new_group->id.us--;
if (new_group->id.lib != library) {
Member

Is this semantically the same as comparing to nullptr here?

Is this semantically the same as comparing to `nullptr` here?
Author
Member

Semantically I think it's different. This is really asking "do we have to move the data-block to a different library.

Physically I think it's the same (though that assumes a new data-blocks .lib pointer is always nullptr, which I'm not 100% sure about with the curlib stuff. So I'd rather be safe here since this check doesn't hurt.

Semantically I think it's different. This is really asking "do we have to move the data-block to a different library. Physically I think it's the same (though that assumes a new data-blocks `.lib` pointer is always `nullptr`, which I'm not 100% sure about with the `curlib` stuff. So I'd rather be safe here since this check doesn't hurt.
@ -2276,0 +2382,4 @@
/* Move the node group to the requested library so that library data-blocks don't point to
* local data-blocks. This requires making sure the name is unique in that library and
* changing the name maps to be consistent with the new state. */
new_group->id.lib = library;
Member

Are there other places which move something into a library after it has been created? Seems ok, but don't know if just setting this one property is enough to make it part of the library.

Are there other places which move something into a library after it has been created? Seems ok, but don't know if just setting this one property is enough to make it part of the library.
Author
Member

As far as I can tell (reading other code that does ->lib = ), yeah, this looks like enough. Bastien also said this:

trivial to fix now in main, using the new BKE_id_new_in_lib functions. In 4.1, I can only think of creating a local nodetree, assigning the library to it, and re-running the uniquename/sorting code (BKE_id_new_name_validate) on it to ensure it ends up where it should and does have a unique name in the library namespace.

As far as I can tell (reading other code that does `->lib = `), yeah, this looks like enough. Bastien also said this: >trivial to fix now in main, using the new BKE_id_new_in_lib functions. In 4.1, I can only think of creating a local nodetree, assigning the library to it, and re-running the uniquename/sorting code (BKE_id_new_name_validate) on it to ensure it ends up where it should and does have a unique name in the library namespace.
Member

Out of the flags I checked, LIB_TAG_EXTERN may need to be set, but hard to say for sure.

Out of the flags I checked, `LIB_TAG_EXTERN` may need to be set, but hard to say for sure.

I think LIB_TAG_INDIRECT should be set, which means linked indirectly through another linked datablock. LIB_TAG_EXTERN means linked directly.

I think `LIB_TAG_INDIRECT` should be set, which means linked indirectly through another linked datablock. `LIB_TAG_EXTERN` means linked directly.

One thing I would suggest to test is to link an object datablock like this, and then make it local. See if it gets correctly converted.

One thing I would suggest to test is to link an object datablock like this, and then make it local. See if it gets correctly converted.
Author
Member

When I make a linked object local, the node group remains linked. The object's mesh data does too though, so I wouldn't expect the node group to become local.

Semantically LIB_TAG_INDIRECT makes sense though, so I'll add the tag (it didn't change the object make local behavior anyway).

I also checked "Make Local" on the node group itself, that does work.

When I make a linked object local, the node group remains linked. The object's mesh data does too though, so I wouldn't expect the node group to become local. Semantically `LIB_TAG_INDIRECT` makes sense though, so I'll add the tag (it didn't change the object make local behavior anyway). I also checked "Make Local" on the node group itself, that does work.
Hans Goudey added 4 commits 2024-03-18 18:29:39 +01:00
Jacques Lucke approved these changes 2024-03-18 18:44:38 +01:00
Jacques Lucke left a comment
Member

Also fixes the bug I was investigating this morning in Simons file.

Also fixes the bug I was investigating this morning in Simons file.
@ -37,2 +37,4 @@
#include "BKE_idprop.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_main_namemap.hh"
Member

Might need #include "BKE_node_runtime.hh" for .all_nodes().

Might need `#include "BKE_node_runtime.hh"` for `.all_nodes()`.
Author
Member

Already there :)

Already there :)
HooglyBoogly marked this conversation as resolved
Hans Goudey added 1 commit 2024-03-18 19:04:46 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
b3b931e726
Remove unnecessary include
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey added 2 commits 2024-03-18 19:48:44 +01:00
Brecht Van Lommel approved these changes 2024-03-18 20:00:08 +01:00
Brecht Van Lommel left a comment
Owner

Code looks good, seems to work fine in testing.

Code looks good, seems to work fine in testing.
Hans Goudey merged commit 5bfe6ad8f8 into blender-v4.1-release 2024-03-18 20:15:45 +01:00
Hans Goudey deleted branch fix-auto-smooth-versioning 2024-03-18 20:15:52 +01:00

This unfortunately causes a crash for me on the Amy Restaurant demo file:

ERROR (bke.main_namemap): /home/sybren/workspace/blender-git/blender/source/blender/blenkernel/intern/main_namemap.cc:585 main_namemap_validate_and_fix: ID name 'NTAuto Smooth.001' (from library '<None>') is listed in the namemap, but does not exists in current Main
ERROR (bke.main_namemap): /home/sybren/workspace/blender-git/blender/source/blender/blenkernel/intern/main_namemap.cc:585 main_namemap_validate_and_fix: ID name 'NTAuto Smooth.002' (from library '<None>') is listed in the namemap, but does not exists in current Main
blenderdebug() [0x9610a9b]
blenderdebug() [0xc905aba]
blenderdebug() [0xc117547]
blenderdebug() [0x96c6045]
blenderdebug() [0x96bc85a]
blenderdebug() [0x96bc71a]
blenderdebug() [0xccbb8b3]
blenderdebug() [0x96965cd]
blenderdebug() [0x96963ba]
blenderdebug() [0xc93700e]
blenderdebug() [0x9695d54]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f7c1227ed90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f7c1227ee40]
blenderdebug() [0x95d4f65]
BLI_assert failed: /home/sybren/workspace/blender-git/blender/source/blender/blenkernel/intern/blendfile.cc:942, setup_app_data(), at 'BKE_main_namemap_validate(bmain)'
This unfortunately causes a crash for me on the [Amy Restaurant demo file](https://studio.blender.org/characters/5f1ed640e9115ed35ea4b3fb/showcase/1/): ``` ERROR (bke.main_namemap): /home/sybren/workspace/blender-git/blender/source/blender/blenkernel/intern/main_namemap.cc:585 main_namemap_validate_and_fix: ID name 'NTAuto Smooth.001' (from library '<None>') is listed in the namemap, but does not exists in current Main ERROR (bke.main_namemap): /home/sybren/workspace/blender-git/blender/source/blender/blenkernel/intern/main_namemap.cc:585 main_namemap_validate_and_fix: ID name 'NTAuto Smooth.002' (from library '<None>') is listed in the namemap, but does not exists in current Main blenderdebug() [0x9610a9b] blenderdebug() [0xc905aba] blenderdebug() [0xc117547] blenderdebug() [0x96c6045] blenderdebug() [0x96bc85a] blenderdebug() [0x96bc71a] blenderdebug() [0xccbb8b3] blenderdebug() [0x96965cd] blenderdebug() [0x96963ba] blenderdebug() [0xc93700e] blenderdebug() [0x9695d54] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f7c1227ed90] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f7c1227ee40] blenderdebug() [0x95d4f65] BLI_assert failed: /home/sybren/workspace/blender-git/blender/source/blender/blenkernel/intern/blendfile.cc:942, setup_app_data(), at 'BKE_main_namemap_validate(bmain)' ```
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#119539
No description provided.