b44fbc3ce45e3800fa345ed9820b5cd7a4666793
[blender.git] / source / blender / editors / mesh / editmesh_undo.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * ***** END GPL LICENSE BLOCK *****
19  */
20
21 /** \file blender/editors/mesh/editmesh_undo.c
22  *  \ingroup edmesh
23  */
24
25 #include "MEM_guardedalloc.h"
26
27 #include "DNA_mesh_types.h"
28 #include "DNA_object_types.h"
29 #include "DNA_key_types.h"
30
31 #include "BLI_listbase.h"
32
33 #include "BKE_DerivedMesh.h"
34 #include "BKE_context.h"
35 #include "BKE_key.h"
36 #include "BKE_mesh.h"
37 #include "BKE_editmesh.h"
38
39 #include "ED_mesh.h"
40 #include "ED_util.h"
41
42 #define USE_ARRAY_STORE
43
44 #ifdef USE_ARRAY_STORE
45 // #  define DEBUG_PRINT
46 // #  define DEBUG_TIME
47 #  ifdef DEBUG_TIME
48 #    include "PIL_time_utildefines.h"
49 #  endif
50
51 #  include "BLI_array_store.h"
52 #  include "BLI_array_store_utils.h"
53    /* check on best size later... */
54 #  define ARRAY_CHUNK_SIZE 256
55
56 #  define USE_ARRAY_STORE_THREAD
57 #endif
58
59 #ifdef USE_ARRAY_STORE_THREAD
60 #  include "BLI_task.h"
61 #endif
62
63
64 #ifdef USE_ARRAY_STORE
65
66 /* Single linked list of layers stored per type */
67 typedef struct BArrayCustomData {
68         struct BArrayCustomData *next;
69         CustomDataType type;
70         int states_len;  /* number of layers for each type */
71         BArrayState *states[0];
72 } BArrayCustomData;
73
74 #endif
75
76 typedef struct UndoMesh {
77         Mesh me;
78         int selectmode;
79
80         /** \note
81          * this isn't a prefect solution, if you edit keys and change shapes this works well (fixing [#32442]),
82          * but editing shape keys, going into object mode, removing or changing their order,
83          * then go back into editmode and undo will give issues - where the old index will be out of sync
84          * with the new object index.
85          *
86          * There are a few ways this could be made to work but for now its a known limitation with mixing
87          * object and editmode operations - Campbell */
88         int shapenr;
89
90 #ifdef USE_ARRAY_STORE
91         /* NULL arrays are considered empty */
92         struct { /* most data is stored as 'custom' data */
93                 BArrayCustomData *vdata, *edata, *ldata, *pdata;
94                 BArrayState **keyblocks;
95                 BArrayState *mselect;
96         } store;
97 #endif  /* USE_ARRAY_STORE */
98 } UndoMesh;
99
100
101 #ifdef USE_ARRAY_STORE
102
103 /** \name Array Store
104  * \{ */
105
106 static struct {
107         struct BArrayStore_AtSize bs_stride;
108         int users;
109
110         /* We could have the undo API pass in the previous state, for now store a local list */
111         ListBase local_links;
112
113 #ifdef USE_ARRAY_STORE_THREAD
114                 TaskPool *task_pool;
115 #endif
116
117 } um_arraystore = {NULL};
118
119 static void um_arraystore_cd_compact(
120         struct CustomData *cdata, const size_t data_len,
121         bool create,
122         const BArrayCustomData *bcd_reference,
123         BArrayCustomData **r_bcd_first)
124 {
125         if (data_len == 0) {
126                 if (create) {
127                         *r_bcd_first = NULL;
128                 }
129         }
130
131         const BArrayCustomData *bcd_reference_current = bcd_reference;
132         BArrayCustomData *bcd = NULL, *bcd_first = NULL, *bcd_prev = NULL;
133         for (int layer_start = 0, layer_end; layer_start < cdata->totlayer; layer_start = layer_end) {
134                 const CustomDataType type = cdata->layers[layer_start].type;
135
136                 layer_end = layer_start + 1;
137                 while ((layer_end < cdata->totlayer) &&
138                        (type == cdata->layers[layer_end].type))
139                 {
140                         layer_end++;
141                 }
142
143                 const int stride = CustomData_sizeof(type);
144                 BArrayStore *bs = create ? BLI_array_store_at_size_ensure(&um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE) : NULL;
145                 const int layer_len = layer_end - layer_start;
146
147                 if (create) {
148                         if (bcd_reference_current && (bcd_reference_current->type == type)) {
149                                 /* common case, the reference is aligned */
150                         }
151                         else {
152                                 bcd_reference_current = NULL;
153
154                                 /* do a full lookup when un-alligned */
155                                 if (bcd_reference) {
156                                         const BArrayCustomData *bcd_iter = bcd_reference;
157                                         while (bcd_iter) {
158                                                 if (bcd_iter->type == type) {
159                                                         bcd_reference_current = bcd_iter;
160                                                         break;
161                                                 }
162                                                 bcd_iter = bcd_iter->next;
163                                         }
164                                 }
165                         }
166                 }
167
168                 if (create) {
169                         bcd = MEM_callocN(sizeof(BArrayCustomData) + (layer_len * sizeof(BArrayState *)), __func__);
170                         bcd->next = NULL;
171                         bcd->type = type;
172                         bcd->states_len = layer_end - layer_start;
173
174                         if (bcd_prev) {
175                                 bcd_prev->next = bcd;
176                                 bcd_prev = bcd;
177                         }
178                         else {
179                                 bcd_first = bcd;
180                                 bcd_prev  = bcd;
181                         }
182                 }
183
184                 CustomDataLayer *layer = &cdata->layers[layer_start];
185                 for (int i = 0; i < layer_len; i++, layer++) {
186                         if (create) {
187                                 if (layer->data) {
188                                         BArrayState *state_reference =
189                                                 (bcd_reference_current && i < bcd_reference_current->states_len) ?
190                                                  bcd_reference_current->states[i] : NULL;
191                                         bcd->states[i] = BLI_array_store_state_add(
192                                                 bs, layer->data, (size_t)data_len * stride, state_reference);
193                                 }
194                                 else {
195                                         bcd->states[i] = NULL;
196                                 }
197                         }
198
199                         if (layer->data) {
200                                 MEM_freeN(layer->data);
201                                 layer->data = NULL;
202                         }
203                 }
204
205                 if (create) {
206                         if (bcd_reference_current) {
207                                 bcd_reference_current = bcd_reference_current->next;
208                         }
209                 }
210         }
211
212         if (create) {
213                 *r_bcd_first = bcd_first;
214         }
215 }
216
217 /**
218  * \note There is no room for data going out of sync here.
219  * The layers and the states are stored together so this can be kept working.
220  */
221 static void um_arraystore_cd_expand(
222         const BArrayCustomData *bcd, struct CustomData *cdata, const size_t data_len)
223 {
224         CustomDataLayer *layer = cdata->layers;
225         while (bcd) {
226                 const int stride = CustomData_sizeof(bcd->type);
227                 for (int i = 0; i < bcd->states_len; i++) {
228                         BLI_assert(bcd->type == layer->type);
229                         if (bcd->states[i]) {
230                                 size_t state_len;
231                                 layer->data = BLI_array_store_state_data_get_alloc(bcd->states[i], &state_len);
232                                 BLI_assert(stride * data_len == state_len);
233                                 UNUSED_VARS_NDEBUG(stride, data_len);
234                         }
235                         else {
236                                 layer->data = NULL;
237                         }
238                         layer++;
239                 }
240                 bcd = bcd->next;
241         }
242 }
243
244 static void um_arraystore_cd_free(BArrayCustomData *bcd)
245 {
246         while (bcd) {
247                 BArrayCustomData *bcd_next = bcd->next;
248                 const int stride = CustomData_sizeof(bcd->type);
249                 BArrayStore *bs = BLI_array_store_at_size_get(&um_arraystore.bs_stride, stride);
250                 for (int i = 0; i <             bcd->states_len; i++) {
251                         if (bcd->states[i]) {
252                                 BLI_array_store_state_remove(bs, bcd->states[i]);
253                         }
254                 }
255                 MEM_freeN(bcd);
256                 bcd = bcd_next;
257         }
258 }
259
260 /**
261  * \param create: When false, only free the arrays.
262  * This is done since when reading from an undo state, they must be temporarily expanded.
263  * then discarded afterwards, having this argument avoids having 2x code paths.
264  */
265 static void um_arraystore_compact_ex(
266         UndoMesh *um, const UndoMesh *um_ref,
267         bool create)
268 {
269         Mesh *me = &um->me;
270
271         um_arraystore_cd_compact(&me->vdata, me->totvert, create, um_ref ? um_ref->store.vdata : NULL, &um->store.vdata);
272         um_arraystore_cd_compact(&me->edata, me->totedge, create, um_ref ? um_ref->store.edata : NULL, &um->store.edata);
273         um_arraystore_cd_compact(&me->ldata, me->totloop, create, um_ref ? um_ref->store.ldata : NULL, &um->store.ldata);
274         um_arraystore_cd_compact(&me->pdata, me->totpoly, create, um_ref ? um_ref->store.pdata : NULL, &um->store.pdata);
275
276         if (me->key && me->key->totkey) {
277                 const size_t stride = me->key->elemsize;
278                 BArrayStore *bs = create ? BLI_array_store_at_size_ensure(&um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE) : NULL;
279                 if (create) {
280                         um->store.keyblocks = MEM_mallocN(me->key->totkey * sizeof(*um->store.keyblocks), __func__);
281                 }
282                 KeyBlock *keyblock = me->key->block.first;
283                 for (int i = 0; i < me->key->totkey; i++, keyblock = keyblock->next) {
284                         if (create) {
285                                 BArrayState *state_reference =
286                                         (um_ref && um_ref->me.key && (i < um_ref->me.key->totkey)) ?
287                                          um_ref->store.keyblocks[i] : NULL;
288                                 um->store.keyblocks[i] = BLI_array_store_state_add(
289                                         bs, keyblock->data, (size_t)keyblock->totelem * stride,
290                                         state_reference);
291                         }
292
293                         if (keyblock->data) {
294                                 MEM_freeN(keyblock->data);
295                                 keyblock->data = NULL;
296                         }
297                 }
298         }
299
300         if (me->mselect && me->totselect) {
301                 BLI_assert(create == (um->store.mselect == NULL));
302                 if (create) {
303                         BArrayState *state_reference = um_ref ? um_ref->store.mselect : NULL;
304                         const size_t stride = sizeof(*me->mselect);
305                         BArrayStore *bs = BLI_array_store_at_size_ensure(&um_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE);
306                         um->store.mselect = BLI_array_store_state_add(
307                                 bs, me->mselect, (size_t)me->totselect * stride, state_reference);
308                 }
309
310                 /* keep me->totselect for validation */
311                 MEM_freeN(me->mselect);
312                 me->mselect = NULL;
313         }
314
315         if (create) {
316                 um_arraystore.users += 1;
317         }
318
319         BKE_mesh_update_customdata_pointers(me, false);
320 }
321
322 /**
323  * Move data from allocated arrays to de-duplicated states and clear arrays.
324  */
325 static void um_arraystore_compact(UndoMesh *um, const UndoMesh *um_ref)
326 {
327         um_arraystore_compact_ex(um, um_ref, true);
328 }
329
330 static void um_arraystore_compact_with_info(UndoMesh *um, const UndoMesh *um_ref)
331 {
332 #ifdef DEBUG_PRINT
333         size_t size_expanded_prev, size_compacted_prev;
334         BLI_array_store_at_size_calc_memory_usage(&um_arraystore.bs_stride, &size_expanded_prev, &size_compacted_prev);
335 #endif
336
337 #ifdef DEBUG_TIME
338         TIMEIT_START(mesh_undo_compact);
339 #endif
340
341         um_arraystore_compact(um, um_ref);
342
343 #ifdef DEBUG_TIME
344         TIMEIT_END(mesh_undo_compact);
345 #endif
346
347 #ifdef DEBUG_PRINT
348         {
349                 size_t size_expanded, size_compacted;
350                 BLI_array_store_at_size_calc_memory_usage(&um_arraystore.bs_stride, &size_expanded, &size_compacted);
351
352                 const double percent_total = size_expanded ?
353                         (((double)size_compacted / (double)size_expanded) * 100.0) : -1.0;
354
355                 size_t size_expanded_step = size_expanded - size_expanded_prev;
356                 size_t size_compacted_step = size_compacted - size_compacted_prev;
357                 const double percent_step = size_expanded_step ?
358                         (((double)size_compacted_step / (double)size_expanded_step) * 100.0) : -1.0;
359
360                 printf("overall memory use: %.8f%% of expanded size\n", percent_total);
361                 printf("step memory use:    %.8f%% of expanded size\n", percent_step);
362         }
363 #endif
364 }
365
366 #ifdef USE_ARRAY_STORE_THREAD
367
368 struct UMArrayData {
369         UndoMesh *um;
370         const UndoMesh *um_ref;  /* can be NULL */
371 };
372 static void um_arraystore_compact_cb(TaskPool *UNUSED(pool), void *taskdata, int UNUSED(threadid))
373 {
374         struct UMArrayData *um_data = taskdata;
375         um_arraystore_compact_with_info(um_data->um, um_data->um_ref);
376 }
377
378 #endif  /* USE_ARRAY_STORE_THREAD */
379
380 /**
381  * Remove data we only expanded for temporary use.
382  */
383 static void um_arraystore_expand_clear(UndoMesh *um)
384 {
385         um_arraystore_compact_ex(um, NULL, false);
386 }
387
388 static void um_arraystore_expand(UndoMesh *um)
389 {
390         Mesh *me = &um->me;
391
392         um_arraystore_cd_expand(um->store.vdata, &me->vdata, me->totvert);
393         um_arraystore_cd_expand(um->store.edata, &me->edata, me->totedge);
394         um_arraystore_cd_expand(um->store.ldata, &me->ldata, me->totloop);
395         um_arraystore_cd_expand(um->store.pdata, &me->pdata, me->totpoly);
396
397         if (um->store.keyblocks) {
398                 const size_t stride = me->key->elemsize;
399                 KeyBlock *keyblock = me->key->block.first;
400                 for (int i = 0; i < me->key->totkey; i++, keyblock = keyblock->next) {
401                         BArrayState *state = um->store.keyblocks[i];
402                         size_t state_len;
403                         keyblock->data = BLI_array_store_state_data_get_alloc(state, &state_len);
404                         BLI_assert(keyblock->totelem == (state_len / stride));
405                         UNUSED_VARS_NDEBUG(stride);
406                 }
407         }
408
409         if (um->store.mselect) {
410                 const size_t stride = sizeof(*me->mselect);
411                 BArrayState *state = um->store.mselect;
412                 size_t state_len;
413                 me->mselect = BLI_array_store_state_data_get_alloc(state, &state_len);
414                 BLI_assert(me->totselect == (state_len / stride));
415                 UNUSED_VARS_NDEBUG(stride);
416         }
417
418         /* not essential, but prevents accidental dangling pointer access */
419         BKE_mesh_update_customdata_pointers(me, false);
420 }
421
422 static void um_arraystore_free(UndoMesh *um)
423 {
424         Mesh *me = &um->me;
425
426         um_arraystore_cd_free(um->store.vdata);
427         um_arraystore_cd_free(um->store.edata);
428         um_arraystore_cd_free(um->store.ldata);
429         um_arraystore_cd_free(um->store.pdata);
430
431         if (um->store.keyblocks) {
432                 const size_t stride = me->key->elemsize;
433                 BArrayStore *bs = BLI_array_store_at_size_get(&um_arraystore.bs_stride, stride);
434                 for (int i = 0; i < me->key->totkey; i++) {
435                         BArrayState *state = um->store.keyblocks[i];
436                         BLI_array_store_state_remove(bs, state);
437                 }
438                 MEM_freeN(um->store.keyblocks);
439                 um->store.keyblocks = NULL;
440         }
441
442         if (um->store.mselect) {
443                 const size_t stride = sizeof(*me->mselect);
444                 BArrayStore *bs = BLI_array_store_at_size_get(&um_arraystore.bs_stride, stride);
445                 BArrayState *state = um->store.mselect;
446                 BLI_array_store_state_remove(bs, state);
447                 um->store.mselect = NULL;
448         }
449
450         um_arraystore.users -= 1;
451
452         BLI_assert(um_arraystore.users >= 0);
453
454         if (um_arraystore.users == 0) {
455 #ifdef DEBUG_PRINT
456                 printf("mesh undo store: freeing all data!\n");
457 #endif
458                 BLI_array_store_at_size_clear(&um_arraystore.bs_stride);
459
460 #ifdef USE_ARRAY_STORE_THREAD
461                 BLI_task_pool_free(um_arraystore.task_pool);
462                 um_arraystore.task_pool = NULL;
463 #endif
464         }
465
466 }
467
468 /** \} */
469
470 #endif  /* USE_ARRAY_STORE */
471
472
473 /* for callbacks */
474 /* undo simply makes copies of a bmesh */
475 static void *editbtMesh_to_undoMesh(void *emv, void *obdata)
476 {
477
478 #ifdef USE_ARRAY_STORE_THREAD
479         /* changes this waits is low, but must have finished */
480         if (um_arraystore.task_pool) {
481                 BLI_task_pool_work_and_wait(um_arraystore.task_pool);
482         }
483 #endif
484
485         BMEditMesh *em = emv;
486         Mesh *obme = obdata;
487
488         UndoMesh *um = MEM_callocN(sizeof(UndoMesh), "undo Mesh");
489
490         /* make sure shape keys work */
491         um->me.key = obme->key ? BKE_key_copy_nolib(obme->key) : NULL;
492
493         /* BM_mesh_validate(em->bm); */ /* for troubleshooting */
494
495         BM_mesh_bm_to_me(
496                 em->bm, &um->me, (&(struct BMeshToMeshParams){
497                     .cd_mask_extra = CD_MASK_SHAPE_KEYINDEX,
498                 }));
499
500         um->selectmode = em->selectmode;
501         um->shapenr = em->bm->shapenr;
502
503 #ifdef USE_ARRAY_STORE
504         {
505                 /* We could be more clever here,
506                  * the previous undo state may be from a separate mesh. */
507                 const UndoMesh *um_ref = um_arraystore.local_links.last ?
508                                          ((LinkData *)um_arraystore.local_links.last)->data : NULL;
509
510                 /* add oursrlves */
511                 BLI_addtail(&um_arraystore.local_links, BLI_genericNodeN(um));
512
513 #ifdef USE_ARRAY_STORE_THREAD
514                 if (um_arraystore.task_pool == NULL) {
515                         TaskScheduler *scheduler = BLI_task_scheduler_get();
516                         um_arraystore.task_pool = BLI_task_pool_create_background(scheduler, NULL);
517                 }
518
519                 struct UMArrayData *um_data = MEM_mallocN(sizeof(*um_data), __func__);
520                 um_data->um = um;
521                 um_data->um_ref = um_ref;
522
523                 BLI_task_pool_push(
524                         um_arraystore.task_pool,
525                         um_arraystore_compact_cb, um_data, true, TASK_PRIORITY_LOW);
526 #else
527                 um_arraystore_compact_with_info(um, um_ref);
528 #endif
529         }
530 #endif
531
532         return um;
533 }
534
535 static void undoMesh_to_editbtMesh(void *um_v, void *em_v, void *obdata)
536 {
537         BMEditMesh *em = em_v, *em_tmp;
538         Object *ob = em->ob;
539         UndoMesh *um = um_v;
540         BMesh *bm;
541         Key *key = ((Mesh *) obdata)->key;
542
543 #ifdef USE_ARRAY_STORE
544 #ifdef USE_ARRAY_STORE_THREAD
545         /* changes this waits is low, but must have finished */
546         BLI_task_pool_work_and_wait(um_arraystore.task_pool);
547 #endif
548
549 #ifdef DEBUG_TIME
550         TIMEIT_START(mesh_undo_expand);
551 #endif
552
553         um_arraystore_expand(um);
554
555 #ifdef DEBUG_TIME
556         TIMEIT_END(mesh_undo_expand);
557 #endif
558 #endif  /* USE_ARRAY_STORE */
559
560         const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(&um->me);
561
562         em->bm->shapenr = um->shapenr;
563
564         EDBM_mesh_free(em);
565
566         bm = BM_mesh_create(
567                 &allocsize,
568                 &((struct BMeshCreateParams){.use_toolflags = true,}));
569
570         BM_mesh_bm_from_me(
571                 bm, &um->me, (&(struct BMeshFromMeshParams){
572                     .calc_face_normal = true, .active_shapekey = um->shapenr,
573                 }));
574
575         em_tmp = BKE_editmesh_create(bm, true);
576         *em = *em_tmp;
577
578         em->selectmode = um->selectmode;
579         bm->selectmode = um->selectmode;
580         em->ob = ob;
581
582         /* T35170: Restore the active key on the RealMesh. Otherwise 'fake' offset propagation happens
583          *         if the active is a basis for any other. */
584         if (key && (key->type == KEY_RELATIVE)) {
585                 /* Since we can't add, remove or reorder keyblocks in editmode, it's safe to assume
586                  * shapenr from restored bmesh and keyblock indices are in sync. */
587                 const int kb_act_idx = ob->shapenr - 1;
588
589                 /* If it is, let's patch the current mesh key block to its restored value.
590                  * Else, the offsets won't be computed and it won't matter. */
591                 if (BKE_keyblock_is_basis(key, kb_act_idx)) {
592                         KeyBlock *kb_act = BLI_findlink(&key->block, kb_act_idx);
593
594                         if (kb_act->totelem != um->me.totvert) {
595                                 /* The current mesh has some extra/missing verts compared to the undo, adjust. */
596                                 MEM_SAFE_FREE(kb_act->data);
597                                 kb_act->data = MEM_mallocN((size_t)(key->elemsize * bm->totvert), __func__);
598                                 kb_act->totelem = um->me.totvert;
599                         }
600
601                         BKE_keyblock_update_from_mesh(&um->me, kb_act);
602                 }
603         }
604
605         ob->shapenr = um->shapenr;
606
607         MEM_freeN(em_tmp);
608
609 #ifdef USE_ARRAY_STORE
610         um_arraystore_expand_clear(um);
611 #endif
612 }
613
614 static void free_undo(void *um_v)
615 {
616         UndoMesh *um = um_v;
617         Mesh *me = &um->me;
618
619 #ifdef USE_ARRAY_STORE
620
621 #ifdef USE_ARRAY_STORE_THREAD
622         /* changes this waits is low, but must have finished */
623         BLI_task_pool_work_and_wait(um_arraystore.task_pool);
624 #endif
625
626         /* we need to expand so any allocations in custom-data are freed with the mesh */
627         um_arraystore_expand(um);
628
629         {
630                 LinkData *link = BLI_findptr(&um_arraystore.local_links, um, offsetof(LinkData, data));
631                 BLI_remlink(&um_arraystore.local_links, link);
632                 MEM_freeN(link);
633         }
634         um_arraystore_free(um);
635 #endif
636
637         if (me->key) {
638                 BKE_key_free(me->key);
639                 MEM_freeN(me->key);
640         }
641
642         BKE_mesh_free(me);
643         MEM_freeN(me);
644 }
645
646 static void *getEditMesh(bContext *C)
647 {
648         Object *obedit = CTX_data_edit_object(C);
649         if (obedit && obedit->type == OB_MESH) {
650                 Mesh *me = obedit->data;
651                 return me->edit_btmesh;
652         }
653         return NULL;
654 }
655
656 /* and this is all the undo system needs to know */
657 void undo_push_mesh(bContext *C, const char *name)
658 {
659         /* em->ob gets out of date and crashes on mesh undo,
660          * this is an easy way to ensure its OK
661          * though we could investigate the matter further. */
662         Object *obedit = CTX_data_edit_object(C);
663         BMEditMesh *em = BKE_editmesh_from_object(obedit);
664         em->ob = obedit;
665
666         undo_editmode_push(C, name, getEditMesh, free_undo, undoMesh_to_editbtMesh, editbtMesh_to_undoMesh, NULL);
667 }