Fix and regression test for crash during node group updates #104696

Closed
Lukas Tönne wants to merge 4 commits from LukasTonne/blender:nodes-undefined-group-tree-update-crash into main

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

Node tree updates can crash if the tree contains a node group that points at an
"undefined" tree type. This can happen if the tree is linked from a library
and the path is lost, or if a custom (python) tree is used and the script is not
run.

The fix is to check if the node group type is valid ("registered") and return an empty list otherwise.

A regression test has been added to test updates with undefined group trees in future.

Node tree updates can crash if the tree contains a node group that points at an "undefined" tree type. This can happen if the tree is linked from a library and the path is lost, or if a custom (python) tree is used and the script is not run. The fix is to check if the node group type is valid ("registered") and return an empty list otherwise. A regression test has been added to test updates with undefined group trees in future.
Brecht Van Lommel added this to the Nodes & Physics project 2023-02-13 19:00:26 +01:00
Lukas Tönne requested review from Jacques Lucke 2023-03-07 10:46:42 +01:00
Jacques Lucke requested changes 2023-03-07 10:58:57 +01:00
@ -0,0 +27,4 @@
namespace blender::bke::node::tests {
struct NodeTreeTestContext {
Member

Did you use some other tests as reference here? How to decide what goes into NodeTreeTestContext and what into NodeTreeTest?

Generally, I think the fix can be committed first without this test, but it's interesting to see how we could test this. Wouldn't mind adding this test separately, but I'd want to check if this is really initializing all the things that would have to be initialized.

Did you use some other tests as reference here? How to decide what goes into `NodeTreeTestContext` and what into `NodeTreeTest`? Generally, I think the fix can be committed first without this test, but it's interesting to see how we could test this. Wouldn't mind adding this test separately, but I'd want to check if this is really initializing all the things that would have to be initialized.
Author
Member

Yes, i copied most of this from other tests, e.g. blend_file_loading_base_test.cc, lib_id_test.cc.

I only used the necessary parts for making node trees ID blocks and updating them. All the stuff in SetUpTestSuite/TearDownTestSuite is for one-off initialization that can stay over multiple tests. The "context" is temporary stuff (make new Main and a context) that gets thrown away after each test. Could do that in the virtual SetUp/TearDown for each fixture, but i like the explicitness of the "context". No strong opinion.

Yes, i copied most of this from other tests, e.g. `blend_file_loading_base_test.cc`, `lib_id_test.cc`. I only used the necessary parts for making node trees ID blocks and updating them. All the stuff in `SetUpTestSuite`/`TearDownTestSuite` is for one-off initialization that can stay over multiple tests. The "context" is temporary stuff (make new `Main` and a context) that gets thrown away after each test. Could do that in the virtual `SetUp`/`TearDown` for each fixture, but i like the explicitness of the "context". No strong opinion.
Author
Member

Here's a for just the fix, into the release branch: #105564

Here's a for just the fix, into the release branch: #105564
@ -23,6 +23,11 @@ static const aal::RelationsInNode &get_relations_in_node(const bNode &node, Reso
{
if (node.is_group()) {
if (const bNodeTree *group = reinterpret_cast<const bNodeTree *>(node.id)) {
/* Undefined tree types have no relations */
Member

Comment style, missing dot. Same in other places.

Comment style, missing dot. Same in other places.
LukasTonne marked this conversation as resolved
@ -24,2 +24,4 @@
if (node.is_group()) {
if (const bNodeTree *group = reinterpret_cast<const bNodeTree *>(node.id)) {
/* Undefined tree types have no relations */
if (!ntreeIsRegistered(const_cast<bNodeTree *>(group))) {
Member

Better change ntreeIsRegistered to take a const node tree.

Better change `ntreeIsRegistered` to take a `const` node tree.

This has already been done, so you can simply remove the const cast

This has already been done, so you can simply remove the const cast
LukasTonne marked this conversation as resolved
Lukas Tönne force-pushed nodes-undefined-group-tree-update-crash from b83c2a2548 to 6677d69fbc 2023-03-08 11:58:31 +01:00 Compare
Member

I kind of don't like the fact that adding node tests requires another Blender entry point that needs to call BKE_idtype_init and the like... This does not feel like a scalable solution. Comments like this (in BlendfileLoadingBaseTest::SetUpTestCase) also show that this approach can be quite brittle and can lead to a fair amount of code duplication:

Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from main() in creator.c.

I'd be more happy with a solution that just starts up Blender as usual and then runs some test code. This is the approach used by Python tests and by extension also geometry nodes tests.

Duplicating the initialization and teardown logic once for tests (besides main and WM_exit_ex) might be ok, but more than that seems to be like too much duplication for me...

I kind of don't like the fact that adding node tests requires another Blender entry point that needs to call `BKE_idtype_init` and the like... This does not feel like a scalable solution. Comments like this (in `BlendfileLoadingBaseTest::SetUpTestCase`) also show that this approach can be quite brittle and can lead to a fair amount of code duplication: > Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from main() in creator.c. I'd be more happy with a solution that just starts up Blender as usual and then runs some test code. This is the approach used by Python tests and by extension also geometry nodes tests. Duplicating the initialization and teardown logic once for tests (besides `main` and `WM_exit_ex`) might be ok, but more than that seems to be like too much duplication for me...
Lukas Tönne closed this pull request 2024-04-19 14:18:47 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
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 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#104696
No description provided.