Yet another fix for crashes when drawing empty base mesh with constructive modifier...
authorLukas Toenne <lukas.toenne@googlemail.com>
Mon, 21 Nov 2011 11:46:05 +0000 (11:46 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Mon, 21 Nov 2011 11:46:05 +0000 (11:46 +0000)
The real reason for this crash is that ocean modifier (in generative setting) does not properly set the derived mesh face ORIGINDEX data to ORIGINDEX_NONE. With this the previous fixes are not necessary.

source/blender/editors/space_view3d/drawobject.c
source/blender/modifiers/intern/MOD_ocean.c

index 58d9c85..baf977e 100644 (file)
@@ -2735,35 +2735,29 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
        if(dt>OB_WIRE) {
                if(CHECK_OB_DRAWTEXTURE(v3d, dt)) {
                        if(draw_glsl_material(scene, ob, v3d, dt)) {
-                               /* if em has no faces the drawMappedFaces callback will fail */
-                               if(em->faces.first) {
-                                       glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
-
-                                       finalDM->drawMappedFacesGLSL(finalDM, GPU_enable_material,
-                                                                                                draw_em_fancy__setGLSLFaceOpts, NULL);
-                                       GPU_disable_material();
-
-                                       glFrontFace(GL_CCW);
-                               }
+                               glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
+                               
+                               finalDM->drawMappedFacesGLSL(finalDM, GPU_enable_material,
+                                                            draw_em_fancy__setGLSLFaceOpts, NULL);
+                               GPU_disable_material();
+                               
+                               glFrontFace(GL_CCW);
                        }
                        else {
                                draw_mesh_textured(scene, v3d, rv3d, ob, finalDM, 0);
                        }
                }
                else {
-                       /* if em has no faces the drawMappedFaces callback will fail */
-                       if(em->faces.first) {
-                               /* 3 floats for position, 3 for normal and times two because the faces may actually be quads instead of triangles */
-                               glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED);
-
-                               glEnable(GL_LIGHTING);
-                               glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
-
-                               finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, NULL, 0, GPU_enable_material, NULL);
-
-                               glFrontFace(GL_CCW);
-                               glDisable(GL_LIGHTING);
-                       }
+                       /* 3 floats for position, 3 for normal and times two because the faces may actually be quads instead of triangles */
+                       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED);
+                       
+                       glEnable(GL_LIGHTING);
+                       glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
+                       
+                       finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, NULL, 0, GPU_enable_material, NULL);
+                       
+                       glFrontFace(GL_CCW);
+                       glDisable(GL_LIGHTING);
                }
                        
                // Setup for drawing wire over, disable zbuffer
index 3ba49f2..db98c22 100644 (file)
@@ -277,6 +277,7 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
        MVert *mv;
        MFace *mf;
        MTFace *tf;
+       int *origindex;
 
        int cdlayer;
 
@@ -305,6 +306,7 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
 
        mv = CDDM_get_verts(result);
        mf = CDDM_get_faces(result);
+       origindex= result->getFaceDataArray(result, CD_ORIGINDEX);
 
        /* create vertices */
        #pragma omp parallel for private(x, y) if (rx > OMP_MIN_RES)
@@ -329,6 +331,9 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
                        mf[fi].v4 = vi + res_x+1;
 
                        mf[fi].flag |= ME_SMOOTH;
+
+                       /* generated geometry does not map to original faces */
+                       origindex[fi] = ORIGINDEX_NONE;
                }
        }