From 9a7f6e937bc80b9e72b503d0b0fb07ea840a3e38 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 14 Dec 2009 17:08:02 +0000 Subject: [PATCH] Fix #20345: weight paint crashes with armature modifier without object. Also fixes: * Weight paint subsurf drawing. * Missing pointer endian conversion in paint brushes. * Use of unitialized variable in screen version patch. * Multires modifier without mdisps layer crash. --- .../blender/blenkernel/intern/cdderivedmesh.c | 1 - source/blender/blenkernel/intern/multires.c | 7 ++ .../blender/blenkernel/intern/subsurf_ccg.c | 77 ++++++++++++++----- source/blender/blenloader/intern/readfile.c | 19 +++-- .../editors/sculpt_paint/paint_vertex.c | 19 +++-- 5 files changed, 87 insertions(+), 36 deletions(-) diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 77ad9fb7a7b..66c39c6571a 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -761,7 +761,6 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us float *nors= dm->getFaceDataArray(dm, CD_NORMAL); int i, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX); - mc = DM_get_face_data_layer(dm, CD_ID_MCOL); if(!mc) mc = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 66f8da03d24..139a8d3267f 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -450,6 +450,13 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, int invert, int int *gridOffset; int i, numGrids, gridSize, dGridSize, dSkip; + if(!mdisps) { + if(invert) + mdisps = CustomData_add_layer(&me->fdata, CD_MDISPS, CD_DEFAULT, NULL, me->totface); + else + return; + } + numGrids = dm->getNumGrids(dm); gridSize = dm->getGridSize(dm); gridData = dm->getGridData(dm); diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index f6abedda2b6..793ea26a602 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -1548,12 +1548,15 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, { CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; CCGSubSurf *ss = ccgdm->ss; - MCol *mcol = DM_get_face_data_layer(dm, CD_MCOL); + MCol *mcol = dm->getFaceDataArray(dm, CD_WEIGHT_MCOL); MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE); char *faceFlags = ccgdm->faceFlags; int i, totface, flag, gridSize = ccgSubSurf_getGridSize(ss); int gridFaces = gridSize - 1; + if(!mcol) + mcol = dm->getFaceDataArray(dm, CD_MCOL); + totface = ccgSubSurf_getNumFaces(ss); for(i = 0; i < totface; i++) { CCGFace *f = ccgdm->faceMap[i].face; @@ -1719,21 +1722,35 @@ static void ccgDM_drawUVEdges(DerivedMesh *dm) static void ccgDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; CCGSubSurf *ss = ccgdm->ss; - CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss); + MCol *mcol= NULL; int i, gridSize = ccgSubSurf_getGridSize(ss); char *faceFlags = ccgdm->faceFlags; + int gridFaces = gridSize - 1, totface; - for (i=0; !ccgFaceIterator_isStopped(fi); i++,ccgFaceIterator_next(fi)) { - CCGFace *f = ccgFaceIterator_getCurrent(fi); + if(useColors) { + mcol = dm->getFaceDataArray(dm, CD_WEIGHT_MCOL); + if(!mcol) + mcol = dm->getFaceDataArray(dm, CD_MCOL); + } + + totface = ccgSubSurf_getNumFaces(ss); + for(i = 0; i < totface; i++) { + CCGFace *f = ccgdm->faceMap[i].face; int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f); int drawSmooth, index = ccgDM_getFaceMapIndex(ss, f); int origIndex; + unsigned char *cp= NULL; origIndex = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(ss, f)); if(faceFlags) drawSmooth = (faceFlags[origIndex*2] & ME_SMOOTH); else drawSmooth = 1; - + + if(mcol) { + cp= (unsigned char*)mcol; + mcol += gridFaces*gridFaces*numVerts*4; + } + if (index!=-1) { int draw; draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, index, &drawSmooth); @@ -1748,41 +1765,61 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *u DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S); if (drawSmooth) { glShadeModel(GL_SMOOTH); - for (y=0; yno); glVertex3fv(a->co); + if(cp) glColor3ub(cp[7], cp[6], cp[5]); glNormal3fv(b->no); glVertex3fv(b->co); + + if(x != gridFaces-1) { + if(cp) cp += 16; + } } + + a = &faceGridData[(y+0)*gridSize + x]; + b = &faceGridData[(y+1)*gridSize + x]; + + if(cp) glColor3ub(cp[15], cp[14], cp[13]); + glNormal3fv(a->no); + glVertex3fv(a->co); + if(cp) glColor3ub(cp[11], cp[10], cp[9]); + glNormal3fv(b->no); + glVertex3fv(b->co); + + if(cp) cp += 16; + glEnd(); } } else { glShadeModel(GL_FLAT); glBegin(GL_QUADS); - for (y=0; ypaint_cursor= NULL; - (*paint)->brushes= newdataadr(fd, (*paint)->brushes); + Paint *p; + + p= (*paint)= newdataadr(fd, (*paint)); + if(p) { + p->paint_cursor= NULL; + p->brushes= newdataadr(fd, p->brushes); + test_pointer_array(fd, (void**)&p->brushes); } } @@ -4309,6 +4312,7 @@ static void direct_link_scene(FileData *fd, Scene *sce) direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint); sce->toolsettings->imapaint.paint.brushes= newdataadr(fd, sce->toolsettings->imapaint.paint.brushes); + test_pointer_array(fd, (void**)&sce->toolsettings->imapaint.paint.brushes); sce->toolsettings->imapaint.paintcursor= NULL; sce->toolsettings->particle.paintcursor= NULL; @@ -10115,8 +10119,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } /* clear hanging 'temp' screens from older 2.5 files*/ if (main->versionfile == 250) { - bScreen *screen; - for(screen= main->screen.first; screen; screen= screen->id.next) { + bScreen *screen, *nextscreen; + + for(screen= main->screen.first; screen; screen= nextscreen) { + nextscreen= screen->id.next; + if (screen->full == SCREENTEMP) free_libblock(&main->screen, screen); } diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 7021d76b1c4..56e020e22aa 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1300,15 +1300,18 @@ static char *wpaint_make_validmap(Mesh *me, Object *ob) if (md->type == eModifierType_Armature) { amd = (ArmatureModifierData*) md; - pose = amd->object->pose; - - for (chan=pose->chanbase.first; chan; chan=chan->next) { - if (chan->bone->flag & BONE_NO_DEFORM) - continue; - if (BLI_ghash_haskey(gh, chan->name)) { - BLI_ghash_remove(gh, chan->name, NULL, NULL); - BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1)); + if(amd->object && amd->object->pose) { + pose = amd->object->pose; + + for (chan=pose->chanbase.first; chan; chan=chan->next) { + if (chan->bone->flag & BONE_NO_DEFORM) + continue; + + if (BLI_ghash_haskey(gh, chan->name)) { + BLI_ghash_remove(gh, chan->name, NULL, NULL); + BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1)); + } } } }