Fix #30089: crash with cycles viewport rendering while in text edit mode.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 7 Feb 2012 18:08:15 +0000 (18:08 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 7 Feb 2012 18:08:15 +0000 (18:08 +0000)
Cause was Object.to_mesh(), which could cause invalid memory access when
calling it on text objects in edit mode.

source/blender/makesrna/intern/rna_object_api.c

index 188ccccbfc41760adec1c96e36c340be68a6e1f5..9a90499d7df2979bea485e3723f18354e2809210 100644 (file)
@@ -80,7 +80,7 @@
 Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_modifiers, int settings)
 {
        Mesh *tmpmesh;
-       Curve *tmpcu = NULL;
+       Curve *tmpcu = NULL, *copycu;
        Object *tmpobj = NULL;
        int render = settings == eModifierMode_Render, i;
        int cage = !apply_modifiers;
@@ -101,22 +101,20 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_
                        object_free_modifiers(tmpobj);
 
                /* copies the data */
-               tmpobj->data = copy_curve( (Curve *) ob->data );
+               copycu = tmpobj->data = copy_curve( (Curve *) ob->data );
 
-#if 0
-               /* copy_curve() sets disp.first null, so currently not need */
-               {
-                       Curve *cu;
-                       cu = (Curve *)tmpobj->data;
-                       if( cu->disp.first )
-                               MEM_freeN( cu->disp.first );
-                       cu->disp.first = NULL;
-               }
-       
-#endif
+               /* temporarily set edit so we get updates from edit mode, but
+                  also because for text datablocks copying it while in edit
+                  mode gives invalid data structures */
+               copycu->editfont = tmpcu->editfont;
+               copycu->editnurb = tmpcu->editnurb;
 
                /* get updated display list, and convert to a mesh */
                makeDispListCurveTypes( sce, tmpobj, 0 );
+
+               copycu->editfont = NULL;
+               copycu->editnurb = NULL;
+
                nurbs_to_mesh( tmpobj );
                
                /* nurbs_to_mesh changes the type to a mesh, check it worked */