Fix #30496: Bugs and crashes about "make links modifers" function.

Was missed check for if modifier is available for particular object type
which ended up with unpredictable results when modifier which isn't supported
yet for some object type as linked to that object type.
This commit is contained in:
Sergey Sharybin 2012-03-12 14:35:07 +00:00
parent 74b7bc1228
commit a527e3ea25
3 changed files with 32 additions and 2 deletions

@ -67,6 +67,8 @@ void update_base_layer(struct Scene *scene, struct Object *ob);
void free_object(struct Object *ob);
void object_free_display(struct Object *ob);
int object_support_modifier_type(struct Object *ob, int modifier_type);
void object_link_modifiers(struct Object *ob, struct Object *from);
void object_free_modifiers(struct Object *ob);

@ -199,16 +199,40 @@ void object_free_modifiers(Object *ob)
object_free_softbody(ob);
}
int object_support_modifier_type(Object *ob, int modifier_type)
{
ModifierTypeInfo *mti;
mti = modifierType_getInfo(modifier_type);
if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) ||
(ob->type==OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh))))
{
return FALSE;
}
return TRUE;
}
void object_link_modifiers(struct Object *ob, struct Object *from)
{
ModifierData *md;
object_free_modifiers(ob);
if (!ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
/* only objects listed above can have modifiers and linking them to objects
* which doesn't have modifiers stack is quite silly */
return;
}
for (md=from->modifiers.first; md; md=md->next) {
ModifierData *nmd = NULL;
if (ELEM4(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance, eModifierType_Collision)) continue;
if (!object_support_modifier_type(ob, md->type))
continue;
nmd = modifier_new(md->type);
modifier_copyData(md, nmd);
BLI_addtail(&ob->modifiers, nmd);
@ -954,6 +978,11 @@ void copy_object_particlesystems(Object *obn, Object *ob)
ParticleSystem *psys, *npsys;
ModifierData *md;
if (obn->type != OB_MESH) {
/* currently only mesh objects can have soft body */
return;
}
obn->particlesystem.first= obn->particlesystem.last= NULL;
for (psys=ob->particlesystem.first; psys; psys=psys->next) {
npsys= copy_particlesystem(psys);

@ -670,8 +670,7 @@ static EnumPropertyItem *modifier_add_itemf(bContext *C, PointerRNA *UNUSED(ptr)
if(mti->flags & eModifierTypeFlag_NoUserAdd)
continue;
if(!((mti->flags & eModifierTypeFlag_AcceptsCVs) ||
(ob->type==OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh))))
if(!object_support_modifier_type(ob, md_item->value))
continue;
}
else {