[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51380] trunk/blender/source/blender/ modifiers/intern/MOD_particleinstance.c: Fix #32887, ParticleInstance: crash with hidden particle system + children.

Lukas Toenne lukas.toenne at googlemail.com
Wed Oct 17 11:49:32 CEST 2012


Revision: 51380
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51380
Author:   lukastoenne
Date:     2012-10-17 09:49:32 +0000 (Wed, 17 Oct 2012)
Log Message:
-----------
Fix #32887, ParticleInstance: crash with hidden particle system + children.

The issue here is that the particle instance modifier (pimd) accesses data from the linked particle system modifier (psmd). This data is only correctly generated when the psmd is enabled; here the design violates the modifier principle of providing valid object data (or rather DM) even when disabled.

The solution in this case is to make a custom isDisabled check for the pimd to see if the psmd is enabled. This means the pimd won't work for disabled psmd, but doesn't crash.

Modified Paths:
--------------
    trunk/blender/source/blender/modifiers/intern/MOD_particleinstance.c

Modified: trunk/blender/source/blender/modifiers/intern/MOD_particleinstance.c
===================================================================
--- trunk/blender/source/blender/modifiers/intern/MOD_particleinstance.c	2012-10-17 04:13:03 UTC (rev 51379)
+++ trunk/blender/source/blender/modifiers/intern/MOD_particleinstance.c	2012-10-17 09:49:32 UTC (rev 51380)
@@ -81,6 +81,44 @@
 {
 	return 0;
 }
+
+static int isDisabled(ModifierData *md, int useRenderParams)
+{
+	ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
+	ParticleSystem *psys;
+	ModifierData *ob_md;
+	
+	if (!pimd->ob)
+		return TRUE;
+	
+	psys = BLI_findlink(&pimd->ob->particlesystem, pimd->psys - 1);
+	if (psys == NULL)
+		return TRUE;
+	
+	/* If the psys modifier is disabled we cannot use its data.
+	 * First look up the psys modifier from the object, then check if it is enabled.
+	 */
+	for (ob_md = pimd->ob->modifiers.first; ob_md; ob_md = ob_md->next) {
+		if (ob_md->type == eModifierType_ParticleSystem) {
+			ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)ob_md;
+			if (psmd->psys == psys) {
+				int required_mode;
+				
+				if (useRenderParams) required_mode = eModifierMode_Render;
+				else required_mode = eModifierMode_Realtime;
+				
+				if (!modifier_isEnabled(md->scene, ob_md, required_mode))
+					return TRUE;
+				
+				break;
+			}
+		}
+	}
+	
+	return FALSE;
+}
+
+
 static void updateDepgraph(ModifierData *md, DagForest *forest,
                            struct Scene *UNUSED(scene),
                            Object *UNUSED(ob),
@@ -384,7 +422,7 @@
 	/* initData */ initData,
 	/* requiredDataMask */ NULL,
 	/* freeData */ NULL,
-	/* isDisabled */ NULL,
+	/* isDisabled */ isDisabled,
 	/* updateDepgraph */ updateDepgraph,
 	/* dependsOnTime */ dependsOnTime,
 	/* dependsOnNormals */ NULL,




More information about the Bf-blender-cvs mailing list