[Bf-blender-cvs] [bcc8639] master: Fix T49273: Crash during access to dupli weights at launch time.

Bastien Montagne noreply at git.blender.org
Wed Sep 7 12:52:14 CEST 2016


Commit: bcc863993adfe019454d2da014528ac922fffd41
Author: Bastien Montagne
Date:   Wed Sep 7 12:45:58 2016 +0200
Branches: master
https://developer.blender.org/rBbcc863993adfe019454d2da014528ac922fffd41

Fix T49273: Crash during access to dupli weights at launch time.

See commit's comments for details, but this boils down to: do not try to use
purely runtime cache data as a 'real' ID pointer in readcode, it's likely
doomed to fail in some cases, and is bad practice in any case!

Thix fix implies dupliweight's object will be invalid until first scene update
(i.e. first particles evaluation).

===================================================================

M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenloader/intern/readfile.c

===================================================================

diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index aecaf85..907521c 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -318,16 +318,24 @@ void psys_check_group_weights(ParticleSettings *part)
 	int current = 0;
 
 	if (part->ren_as == PART_DRAW_GR && part->dup_group && part->dup_group->gobject.first) {
-		/* first remove all weights that don't have an object in the group */
+		/* First try to find NULL objects from their index,
+		 * and remove all weights that don't have an object in the group. */
 		dw = part->dupliweights.first;
 		while (dw) {
-			if (!BKE_group_object_exists(part->dup_group, dw->ob)) {
-				tdw = dw->next;
-				BLI_freelinkN(&part->dupliweights, dw);
-				dw = tdw;
+			if (dw->ob == NULL || !BKE_group_object_exists(part->dup_group, dw->ob)) {
+				GroupObject *go = (GroupObject *)BLI_findlink(&part->dup_group->gobject, dw->index);
+				if (go) {
+					dw->ob = go->ob;
+				}
+				else {
+					tdw = dw->next;
+					BLI_freelinkN(&part->dupliweights, dw);
+					dw = tdw;
+				}
 			}
-			else
+			else {
 				dw = dw->next;
+			}
 		}
 
 		/* then add objects in the group to new list */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 57d499f..60f276b 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4105,8 +4105,14 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
 				if (index_ok) {
 					/* if we have indexes, let's use them */
 					for (dw = part->dupliweights.first; dw; dw = dw->next) {
-						GroupObject *go = (GroupObject *)BLI_findlink(&part->dup_group->gobject, dw->index);
-						dw->ob = go ? go->ob : NULL;
+						/* Do not try to restore pointer here, we have to search for group objects in another
+						 * separated step.
+						 * Reason is, the used group may be linked from another library, which has not yet
+						 * been 'lib_linked'.
+						 * Since dw->ob is not considered as an object user (it does not make objet directly linked),
+						 * we may have no valid way to retrieve it yet.
+						 * See T49273. */
+						dw->ob = NULL;
 					}
 				}
 				else {




More information about the Bf-blender-cvs mailing list