Fix T54326: Import Alembic stuck in edit mode
authorKévin Dietrich <kevin.dietrich@mailoo.org>
Fri, 16 Mar 2018 03:06:18 +0000 (04:06 +0100)
committerKévin Dietrich <kevin.dietrich@mailoo.org>
Fri, 16 Mar 2018 03:06:34 +0000 (04:06 +0100)
Switch to object mode before doing the import.

source/blender/editors/io/io_alembic.c

index ca4ab30..08181af 100644 (file)
@@ -59,6 +59,8 @@
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
 
+#include "ED_object.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -543,6 +545,22 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
                }
        }
 
+       /* Switch to object mode to avoid being stuck in other modes (T54326). */
+       if (CTX_data_mode_enum(C) != CTX_MODE_OBJECT) {
+               Object *obedit = CTX_data_edit_object(C);
+
+               if (obedit != NULL) {
+                       ED_object_mode_toggle(C, obedit->mode);
+               }
+               else {
+                       Object *ob = CTX_data_active_object(C);
+
+                       if (ob) {
+                               ED_object_mode_toggle(C, ob->mode);
+                       }
+               }
+       }
+
        bool ok = ABC_import(C, filename, scale, is_sequence, set_frame_range,
                             sequence_len, offset, validate_meshes,
                             as_background_job);