Fixed crash caused by recent VBO's changes
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 1 Dec 2011 18:26:48 +0000 (18:26 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 1 Dec 2011 18:26:48 +0000 (18:26 +0000)
Crash was caused by non-initialized original index passing to compareDrawOptions
callback. Due to in some cases it's enough to know indices of faces in final DM
(like for comparing if the same texture used for mesh drawing) assume this
callback receives index in final DM and if it's needed it will make conversion
to original index itself.

This should help reaching extra speed if textured object is affected by
bevel modifiers, i.e.

source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c

index 1c2537464c23fd182d35a61360c375d1b709f9b4..aade98ec9da84933b0e24832329aafeb2283a068 100644 (file)
@@ -804,15 +804,9 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                                flush= !flag || i == tottri - 1;
 
                                if(!flush && compareDrawOptions) {
-                                       int next_orig= (index==NULL) ? next_actualFace : index[next_actualFace];
-
-                                       if(orig==ORIGINDEX_NONE || next_orig==ORIGINDEX_NONE) {
-                                               flush= 1;
-                                       } else {
-                                               /* also compare draw options and flush buffer if they're different
-                                                  need for face selection highlight in edit mode */
-                                               flush|= compareDrawOptions(userData, orig, next_orig) == 0;
-                                       }
+                                       /* also compare draw options and flush buffer if they're different
+                                          need for face selection highlight in edit mode */
+                                       flush|= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
                                }
 
                                if(flush) {
@@ -990,15 +984,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                                        flush|= mf[actualFace].mat_nr != mf[next_actualFace].mat_nr;
 
                                        if(!flush && compareDrawOptions) {
-                                               int next_orig= (index==NULL) ? next_actualFace : index[next_actualFace];
-
-                                               if(orig==ORIGINDEX_NONE || next_orig==ORIGINDEX_NONE) {
-                                                       flush= 1;
-                                               } else {
-                                                       /* also compare draw options and flush buffer if they're different
-                                                          need for face selection highlight in edit mode */
-                                                       flush|= compareDrawOptions(userData, orig, next_orig) == 0;
-                                               }
+                                               flush|= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
                                        }
 
                                        if(flush) {
index 690694cb7d9587f680ef4d04da1c8f05bad29216..4fc9c1e283962de3eecff5e1008f880b5be2ccd8 100644 (file)
@@ -631,14 +631,14 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
 
 static int compareDrawOptions(void *userData, int cur_index, int next_index)
 {
-       Mesh *me= (Mesh*) userData;
-       MFace *mf= CustomData_get_layer(&me->fdata, CD_MFACE);
-       MTFace *tf= CustomData_get_layer(&me->fdata, CD_MTFACE);
+       DerivedMesh *dm= (DerivedMesh*) userData;
+       MFace *mf = DM_get_face_data_layer(dm, CD_MFACE);
+       MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE);
 
-       if(mf[cur_index].mat_nr != mf[next_index].mat_nr)
+       if(mf && mf[cur_index].mat_nr != mf[next_index].mat_nr)
                return 0;
 
-       if(tf[cur_index].tpage != tf[next_index].tpage)
+       if(tf && tf[cur_index].tpage != tf[next_index].tpage)
                return 0;
 
        return 1;
@@ -683,7 +683,7 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
                        if(!CustomData_has_layer(&dm->faceData,CD_TEXTURE_MCOL))
                                add_tface_color_layer(dm);
 
-                       dm->drawFacesTex(dm, draw_tface__set_draw, compareDrawOptions, ob->data);
+                       dm->drawFacesTex(dm, draw_tface__set_draw, compareDrawOptions, dm);
                }
        }
 
index c5fa943ae8781c1313f11f22100a750ec8f94917..0bb6f3429cc61c50be9fb50afabf66861173beef 100644 (file)
@@ -2323,7 +2323,7 @@ static void draw_dm_edges_sharp(DerivedMesh *dm)
         * return 2 for the active face so it renders with stipple enabled */
 static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *UNUSED(drawSmooth_r))
 {
-       struct { unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
+       struct { DerivedMesh *dm; unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
        EditFace *efa = EM_get_face_for_index(index);
        unsigned char *col;
        
@@ -2343,11 +2343,18 @@ static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *UNU
 
 static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int next_index)
 {
-       struct { unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
-       EditFace *efa = EM_get_face_for_index(index);
-       EditFace *next_efa = EM_get_face_for_index(next_index);
+       struct { DerivedMesh *dm; unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
+       int *orig_index= DM_get_face_data_layer(data->dm, CD_ORIGINDEX);
+       EditFace *efa;
+       EditFace *next_efa;
        unsigned char *col, *next_col;
 
+       if(!orig_index)
+               return 0;
+
+       efa= EM_get_face_for_index(orig_index[index]);
+       next_efa= EM_get_face_for_index(orig_index[next_index]);
+
        if(efa == next_efa)
                return 1;
 
@@ -2366,7 +2373,8 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
 /* also draws the active face */
 static void draw_dm_faces_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol, unsigned char *actCol, EditFace *efa_act) 
 {
-       struct { unsigned char *cols[3]; EditFace *efa_act; } data;
+       struct { DerivedMesh *dm; unsigned char *cols[3]; EditFace *efa_act; } data;
+       data.dm= dm;
        data.cols[0] = baseCol;
        data.cols[1] = selCol;
        data.cols[2] = actCol;