Fix #28280: Insert Hook wrong index
[blender-staging.git] / source / blender / editors / object / object_hook.c
index bb32869469ac74b21bd22e6f5e1f20b048bd51b6..266556773f09c22a2e6fb6655641d79c343ab318 100644 (file)
@@ -64,6 +64,7 @@
 
 #include "ED_curve.h"
 #include "ED_mesh.h"
+#include "ED_lattice.h"
 #include "ED_screen.h"
 
 #include "WM_types.h"
@@ -292,7 +293,7 @@ static int return_editcurve_indexar(Object *obedit, int *tot, int **indexar, flo
        return totvert;
 }
 
-static int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
+static int object_hook_index_array(Scene *scene, Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
 {
        *indexar= NULL;
        *tot= 0;
@@ -302,7 +303,12 @@ static int object_hook_index_array(Object *obedit, int *tot, int **indexar, char
                case OB_MESH:
                {
                        Mesh *me= obedit->data;
-                       EditMesh *em = BKE_mesh_get_editmesh(me);
+                       EditMesh *em;
+
+                       load_editMesh(scene, obedit);
+                       make_editMesh(scene, obedit);
+
+                       em = BKE_mesh_get_editmesh(me);
 
                        /* check selected vertices first */
                        if( return_editmesh_indexar(em, tot, indexar, cent_r)) {
@@ -316,10 +322,17 @@ static int object_hook_index_array(Object *obedit, int *tot, int **indexar, char
                }
                case OB_CURVE:
                case OB_SURF:
+                       load_editNurb(obedit);
+                       make_editNurb(obedit);
+
                        return return_editcurve_indexar(obedit, tot, indexar, cent_r);
                case OB_LATTICE:
                {
                        Lattice *lt= obedit->data;
+
+                       load_editLatt(obedit);
+                       make_editLatt(obedit);
+
                        return return_editlattice_indexar(lt->editlatt->latt, tot, indexar, cent_r);
                }
                default:
@@ -427,7 +440,7 @@ static void add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *o
        int tot, ok, *indexar;
        char name[32];
        
-       ok = object_hook_index_array(obedit, &tot, &indexar, name, cent);
+       ok = object_hook_index_array(scene, obedit, &tot, &indexar, name, cent);
        
        if (!ok) return;        // XXX error("Requires selected vertices or active Vertex Group");
        
@@ -760,7 +773,7 @@ static int object_hook_assign_exec(bContext *C, wmOperator *op)
        
        /* assign functionality */
        
-       if(!object_hook_index_array(ob, &tot, &indexar, name, cent)) {
+       if(!object_hook_index_array(CTX_data_scene(C), ob, &tot, &indexar, name, cent)) {
                BKE_report(op->reports, RPT_WARNING, "Requires selected vertices or active vertex group");
                return OPERATOR_CANCELLED;
        }