crash when appending object with node group in material #47379

Closed
opened 2016-02-10 10:34:53 +01:00 by Jacques Lucke · 8 comments
Member

System Information
Windows 7/10 64 bit
Nvidia Quadro 600

Blender Version
Broken: 2.76 da7ddb6

Exact steps for others to reproduce the error

  1. Extract the .zip file. Both files have to be in the same directory afterwards.
  2. Open the bug.blend file.
  3. Execute the python script (maybe 2 times)
  4. Crash.

I found out that the node group in the material of the object in the asset.blend file is the problem.
When you open the asset.blend file and remove the node group the crash won't happen.

append_bug.zip

**System Information** Windows 7/10 64 bit Nvidia Quadro 600 **Blender Version** Broken: 2.76 da7ddb6 **Exact steps for others to reproduce the error** 1. Extract the .zip file. Both files have to be in the same directory afterwards. 2. Open the bug.blend file. 3. Execute the python script (maybe 2 times) 4. Crash. I found out that the node group in the material of the object in the asset.blend file is the problem. When you open the asset.blend file and remove the node group the crash won't happen. [append_bug.zip](https://archive.blender.org/developer/F281793/append_bug.zip)
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke

Added subscriber: @brecht

Added subscriber: @brecht

I think the issue is that the nodetree embedded in the material gets inserted into the list of node groups in main, as part of making the material local.

id_clear_lib_data on the material will call ntreeMakeLocal on the embedded node tree, which then calls id_clear_lib_data, which calls new_id that inserts the node tree into the main node group list.

If any developer can think of something better then that would be good since this feels quite hacky, but this is the best fix I found so far.
P323: (An Untitled Masterwork)

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 9c5e5e5..fcb613e 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -85,6 +85,7 @@ void id_sort_by_name(struct ListBase *lb, struct ID *id);
 
 bool new_id(struct ListBase *lb, struct ID *id, const char *name);
 void id_clear_lib_data(struct Main *bmain, struct ID *id);
+void id_clear_lib_data_ex(struct Main *bmain, struct ID *id, bool internal_ntree);
 
 struct ListBase *which_libbase(struct Main *mainlib, short type);
 
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 5d03a42..18a9df2 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -347,7 +347,7 @@ void              ntreeUserDecrefID(struct bNodeTree *ntree);
 
 struct bNodeTree *ntreeFromID(struct ID *id);
 
-void              ntreeMakeLocal(struct bNodeTree *ntree);
+void              ntreeMakeLocal(struct bNodeTree *ntree, bool internal_ntree);
 bool              ntreeHasType(const struct bNodeTree *ntree, int type);
 bool              ntreeHasTree(const struct bNodeTree *ntree, const struct bNodeTree *lookup);
 void              ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 67b6661..ebbc942 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -323,7 +323,7 @@ bool id_make_local(ID *id, bool test)
 			if (!test) BKE_action_make_local((bAction *)id);
 			return true;
 		case ID_NT:
-			if (!test) ntreeMakeLocal((bNodeTree *)id);
+			if (!test) ntreeMakeLocal((bNodeTree *)id, false);
 			return true;
 		case ID_BR:
 			if (!test) BKE_brush_make_local((Brush *)id);
@@ -1654,7 +1654,7 @@ bool new_id(ListBase *lb, ID *id, const char *tname)
  * Pull an ID out of a library (make it local). Only call this for IDs that
  * don't have other library users.
  */
-void id_clear_lib_data(Main *bmain, ID *id)
+void id_clear_lib_data_ex(Main *bmain, ID *id, bool internal_ntree)
 {
 	bNodeTree *ntree = NULL;
 
@@ -1664,7 +1664,8 @@ void id_clear_lib_data(Main *bmain, ID *id)
 
 	id->lib = NULL;
 	id->tag &= ~(LIB_TAG_INDIRECT | LIB_TAG_EXTERN);
-	new_id(which_libbase(bmain, GS(id->name)), id, NULL);
+	if (!internal_ntree)
+		new_id(which_libbase(bmain, GS(id->name)), id, NULL);
 
 	/* internal bNodeTree blocks inside ID types below
 	 * also stores id->lib, make sure this stays in sync.
@@ -1672,7 +1673,7 @@ void id_clear_lib_data(Main *bmain, ID *id)
 	ntree = ntreeFromID(id);
 
 	if (ntree) {
-		ntreeMakeLocal(ntree);
+		ntreeMakeLocal(ntree, true);
 	}
 
 	if (GS(id->name) == ID_OB) {
@@ -1685,6 +1686,11 @@ void id_clear_lib_data(Main *bmain, ID *id)
 	}
 }
 
+void id_clear_lib_data(Main *bmain, ID *id)
+{
+	id_clear_lib_data_ex(bmain, id, false);
+}
+
 /* next to indirect usage in read/writefile also in editobject.c scene.c */
 void BKE_main_id_clear_newpoins(Main *bmain)
 {
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index ad714b8..279c3cd 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -1979,7 +1979,7 @@ static void extern_local_ntree(bNodeTree *ntree)
 	}
 }
 
-void ntreeMakeLocal(bNodeTree *ntree)
+void ntreeMakeLocal(bNodeTree *ntree, bool internal_ntree)
 {
 	Main *bmain = G.main;
 	bool lib = false, local = false;
@@ -1991,7 +1991,7 @@ void ntreeMakeLocal(bNodeTree *ntree)
 	
 	if (ntree->id.lib == NULL) return;
 	if (ntree->id.us == 1) {
-		id_clear_lib_data(bmain, (ID *)ntree);
+		id_clear_lib_data_ex(bmain, (ID *)ntree, internal_ntree);
 		extern_local_ntree(ntree);
 		return;
 	}
@@ -2012,7 +2012,7 @@ void ntreeMakeLocal(bNodeTree *ntree)
 	
 	/* if all users are local, we simply make tree local */
 	if (local && !lib) {
-		id_clear_lib_data(bmain, (ID *)ntree);
+		id_clear_lib_data_ex(bmain, (ID *)ntree, internal_ntree);
 		extern_local_ntree(ntree);
 	}
 	else if (local && lib) {
I think the issue is that the nodetree embedded in the material gets inserted into the list of node groups in main, as part of making the material local. `id_clear_lib_data` on the material will call `ntreeMakeLocal` on the embedded node tree, which then calls `id_clear_lib_data`, which calls `new_id` that inserts the node tree into the main node group list. If any developer can think of something better then that would be good since this feels quite hacky, but this is the best fix I found so far. [P323: (An Untitled Masterwork)](https://archive.blender.org/developer/P323.txt) ``` diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 9c5e5e5..fcb613e 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -85,6 +85,7 @@ void id_sort_by_name(struct ListBase *lb, struct ID *id); bool new_id(struct ListBase *lb, struct ID *id, const char *name); void id_clear_lib_data(struct Main *bmain, struct ID *id); +void id_clear_lib_data_ex(struct Main *bmain, struct ID *id, bool internal_ntree); struct ListBase *which_libbase(struct Main *mainlib, short type); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 5d03a42..18a9df2 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -347,7 +347,7 @@ void ntreeUserDecrefID(struct bNodeTree *ntree); struct bNodeTree *ntreeFromID(struct ID *id); -void ntreeMakeLocal(struct bNodeTree *ntree); +void ntreeMakeLocal(struct bNodeTree *ntree, bool internal_ntree); bool ntreeHasType(const struct bNodeTree *ntree, int type); bool ntreeHasTree(const struct bNodeTree *ntree, const struct bNodeTree *lookup); void ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 67b6661..ebbc942 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -323,7 +323,7 @@ bool id_make_local(ID *id, bool test) if (!test) BKE_action_make_local((bAction *)id); return true; case ID_NT: - if (!test) ntreeMakeLocal((bNodeTree *)id); + if (!test) ntreeMakeLocal((bNodeTree *)id, false); return true; case ID_BR: if (!test) BKE_brush_make_local((Brush *)id); @@ -1654,7 +1654,7 @@ bool new_id(ListBase *lb, ID *id, const char *tname) * Pull an ID out of a library (make it local). Only call this for IDs that * don't have other library users. */ -void id_clear_lib_data(Main *bmain, ID *id) +void id_clear_lib_data_ex(Main *bmain, ID *id, bool internal_ntree) { bNodeTree *ntree = NULL; @@ -1664,7 +1664,8 @@ void id_clear_lib_data(Main *bmain, ID *id) id->lib = NULL; id->tag &= ~(LIB_TAG_INDIRECT | LIB_TAG_EXTERN); - new_id(which_libbase(bmain, GS(id->name)), id, NULL); + if (!internal_ntree) + new_id(which_libbase(bmain, GS(id->name)), id, NULL); /* internal bNodeTree blocks inside ID types below * also stores id->lib, make sure this stays in sync. @@ -1672,7 +1673,7 @@ void id_clear_lib_data(Main *bmain, ID *id) ntree = ntreeFromID(id); if (ntree) { - ntreeMakeLocal(ntree); + ntreeMakeLocal(ntree, true); } if (GS(id->name) == ID_OB) { @@ -1685,6 +1686,11 @@ void id_clear_lib_data(Main *bmain, ID *id) } } +void id_clear_lib_data(Main *bmain, ID *id) +{ + id_clear_lib_data_ex(bmain, id, false); +} + /* next to indirect usage in read/writefile also in editobject.c scene.c */ void BKE_main_id_clear_newpoins(Main *bmain) { diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index ad714b8..279c3cd 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1979,7 +1979,7 @@ static void extern_local_ntree(bNodeTree *ntree) } } -void ntreeMakeLocal(bNodeTree *ntree) +void ntreeMakeLocal(bNodeTree *ntree, bool internal_ntree) { Main *bmain = G.main; bool lib = false, local = false; @@ -1991,7 +1991,7 @@ void ntreeMakeLocal(bNodeTree *ntree) if (ntree->id.lib == NULL) return; if (ntree->id.us == 1) { - id_clear_lib_data(bmain, (ID *)ntree); + id_clear_lib_data_ex(bmain, (ID *)ntree, internal_ntree); extern_local_ntree(ntree); return; } @@ -2012,7 +2012,7 @@ void ntreeMakeLocal(bNodeTree *ntree) /* if all users are local, we simply make tree local */ if (local && !lib) { - id_clear_lib_data(bmain, (ID *)ntree); + id_clear_lib_data_ex(bmain, (ID *)ntree, internal_ntree); extern_local_ntree(ntree); } else if (local && lib) { ```

Added subscriber: @ideasman42

Added subscriber: @ideasman42

@brecht, cant see more elegant way to fix (unless ntrees could be flagged as being in bMain or not).
This could be added as a flag but risks getting out of sync.

Only suggestion is to use more generic name argument for id_clear_lib_data_ex, (id_in_mainlist... id_in_bmain),. eg:

void id_clear_lib_data_ex(struct Main *bmain, struct ID *id, bool id_in_mainlist);

@brecht, cant see more elegant way to fix (unless ntrees could be flagged as being in `bMain` or not). This could be added as a flag but risks getting out of sync. Only suggestion is to use more generic name argument for `id_clear_lib_data_ex`, (id_in_mainlist... id_in_bmain),. eg: `void id_clear_lib_data_ex(struct Main *bmain, struct ID *id, bool id_in_mainlist);`

This issue was referenced by 3c7369164e

This issue was referenced by 3c7369164e0a7edc858b45298bae25c0a20ed0f8

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#47379
No description provided.