- bug fix, hook deform could crash because old files can have hook

indices that are out of range
 - bug fix, hook indicies were not corrected on exit editmode (there
   probably should be a general interface for this kind of patch)
This commit is contained in:
2005-08-10 22:25:32 +00:00
parent 9030e5f686
commit 2b40f19c5b
2 changed files with 56 additions and 10 deletions

View File

@@ -1136,7 +1136,15 @@ static void hookModifier_deformVerts(ModifierData *md, Object *ob, void *derived
Mat4MulSerie(mat, ob->imat, hmd->object->obmat, hmd->parentinv, NULL, NULL, NULL, NULL, NULL);
for (i=0; i<hmd->totindex; i++) {
float *co = vertexCos[hmd->indexar[i]];
int index = hmd->indexar[i];
/* These should always be true and I don't generally like
* "paranoid" style code like this, but old files can have
* indices that are out of range because old blender did
* not correct them on exit editmode.
*/
if (index<numVerts) {
float *co = vertexCos[index];
float fac = hmd->force;
if(hmd->falloff!=0.0) {
@@ -1150,6 +1158,7 @@ static void hookModifier_deformVerts(ModifierData *md, Object *ob, void *derived
VecLerpf(co, co, vec, fac);
}
}
}
}
static void hookModifier_deformVertsEM(ModifierData *md, Object *ob, void *editData, void *derivedData, float (*vertexCos)[3], int numVerts)

View File

@@ -52,6 +52,7 @@
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "DNA_material_types.h"
#include "DNA_modifier_types.h"
#include "DNA_texture_types.h"
#include "DNA_userdef_types.h"
@@ -1194,6 +1195,42 @@ void load_editMesh(void)
me->mcol= 0;
}
/* patch hook indices */
{
Object *ob;
ModifierData *md;
EditVert *eve, **vertMap = NULL;
int i,j;
for (ob=G.main->object.first; ob; ob=ob->id.next) {
for (md=ob->modifiers.first; md; md=md->next) {
if (md->type==eModifierType_Hook) {
HookModifierData *hmd = (HookModifierData*) md;
if (!vertMap) {
vertMap = MEM_callocN(sizeof(*vertMap)*ototvert, "vertMap");
for (eve=em->verts.first; eve; eve=eve->next) {
if (eve->keyindex!=-1)
vertMap[eve->keyindex] = eve;
}
}
for (i=j=0; i<hmd->totindex; i++) {
eve = vertMap[hmd->indexar[i]];
if (eve) {
hmd->indexar[j++] = (long) eve->vn;
}
}
hmd->totindex = j;
}
}
}
if (vertMap) MEM_freeN(vertMap);
}
/* are there keys? */
if(me->key) {