Fix #106246: Crash on deleting the multi-level hierarchy #106374

Closed
Pratik Borhade wants to merge 1 commits from PratikPB2123/blender:T106246-del-hierarchy-crash into main

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

Crash occurs due to accessing the pointer which points to garbage
memory. In brief, base_next points to next base element (base->next) which is
deleted in previous iteration. After BKE_library_ID_is_indirectly_used
call, viewlayer is synced and frees the object_bases list. It results
base_next pointing to garbage memory.
To fix this, point to base->next after BKE_library_ID_is_indirectly_used function call,

Crash occurs due to accessing the pointer which points to garbage memory. In brief, `base_next` points to next base element (`base->next`) which is deleted in previous iteration. After `BKE_library_ID_is_indirectly_used` call, viewlayer is synced and frees the `object_bases` list. It results `base_next` pointing to garbage memory. To fix this, point to `base->next` after `BKE_library_ID_is_indirectly_used` function call,
Pratik Borhade added 1 commit 2023-03-31 12:44:28 +02:00
4b8200666c Fix #106246: Crash on deleting the multi-level hierarchy
Crash occurs due to accessing the pointer which points to garbage
memory. In brief, `base_next` points to next base element (`base->next`) which is
deleted in previous iteration. After `BKE_library_ID_is_indirectly_used`
call, viewlayer is synced and frees the `object_bases` list. It results
`base_next` pointing to garbage memory.
To fix this, point to `base->next` after `BKE_library_ID_is_indirectly_used` function call,
Pratik Borhade requested review from Julian Eisel 2023-03-31 12:44:44 +02:00
Author
Member

I think we can also remove this assignment, no?
As far as I understand, base->next will always be NULL because this object is removed already from the collection/view layer.

I think we can also remove this assignment, no? As far as I understand, `base->next` will always be NULL because this object is removed already from the collection/view layer.
Pratik Borhade added this to the User Interface project 2023-04-03 15:48:56 +02:00
Pratik Borhade added the
Module
User Interface
label 2023-04-03 15:49:05 +02:00
Member

Took me a while to understand what's going on and why this patch fixes it. The collection syncing just happens to be done in a foreach_id callback it seems (from the collection I guess). I think it would be better and more clear to do explicit syncing in the code that does the deletion.

This works for me (but I know too little about the collection syncing to judge):

diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc
index d8d9718ccd6..de632f757e7 100644
--- a/source/blender/editors/space_outliner/outliner_tools.cc
+++ b/source/blender/editors/space_outliner/outliner_tools.cc
@@ -2213,6 +2213,7 @@ static Base *outliner_batch_delete_hierarchy(
 
   DEG_id_tag_update_ex(bmain, &object->id, ID_RECALC_BASE_FLAGS);
   BKE_scene_collections_object_remove(bmain, scene, object, false);
+  BKE_scene_view_layers_synced_ensure(scene);
 
   if (object->id.us == 0) {
     object->id.tag |= LIB_TAG_DOIT;

@mont29 what do you think?

Took me a while to understand what's going on and why this patch fixes it. The collection syncing just happens to be done in a `foreach_id` callback it seems (from the collection I guess). I think it would be better and more clear to do explicit syncing in the code that does the deletion. This works for me (but I know too little about the collection syncing to judge): ```diff diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc index d8d9718ccd6..de632f757e7 100644 --- a/source/blender/editors/space_outliner/outliner_tools.cc +++ b/source/blender/editors/space_outliner/outliner_tools.cc @@ -2213,6 +2213,7 @@ static Base *outliner_batch_delete_hierarchy( DEG_id_tag_update_ex(bmain, &object->id, ID_RECALC_BASE_FLAGS); BKE_scene_collections_object_remove(bmain, scene, object, false); + BKE_scene_view_layers_synced_ensure(scene); if (object->id.us == 0) { object->id.tag |= LIB_TAG_DOIT; ``` @mont29 what do you think?
Julian Eisel requested review from Bastien Montagne 2023-04-05 16:27:32 +02:00
Julian Eisel refused to review 2023-04-05 16:27:41 +02:00

Neither of these changes would fix the root of the issue imho, they just happen to work here because of 'chance' (and probably how allocation of memory works), but the root of the issue is as usual trying to modify data while iterating on it.

Existing code was also uselessly intricate, PR !106821 should hopefully makes things simpler, more efficient and less fragile altogether.

Neither of these changes would fix the root of the issue imho, they just happen to work here because of 'chance' (and probably how allocation of memory works), but the root of the issue is as usual trying to modify data while iterating on it. Existing code was also uselessly intricate, PR !106821 should hopefully makes things simpler, more efficient and less fragile altogether.
Bastien Montagne closed this pull request 2023-04-11 18:33:11 +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 project
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#106374
No description provided.