fix for crash when moving frames about in the node space, was possible to move a...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 5 Aug 2012 20:40:26 +0000 (20:40 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 5 Aug 2012 20:40:26 +0000 (20:40 +0000)
also some minor code cleanup.

source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_draw.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_relationships.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_generics.c

index 00bdbbf..55d9e70 100644 (file)
@@ -359,6 +359,7 @@ void            nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node);
 
 void            nodeToView(struct bNode *node, float x, float y, float *rx, float *ry);
 void            nodeFromView(struct bNode *node, float x, float y, float *rx, float *ry);
+int             nodeAttachNodeCheck(struct bNode *node, struct bNode *parent);
 void            nodeAttachNode(struct bNode *node, struct bNode *parent);
 void            nodeDetachNode(struct bNode *node);
 
index 565e2de..4090b6f 100644 (file)
@@ -592,9 +592,25 @@ void nodeFromView(bNode *node, float x, float y, float *rx, float *ry)
        }
 }
 
+int nodeAttachNodeCheck(bNode *node, bNode *parent)
+{
+       bNode *parent_recurse;
+       for (parent_recurse = node; parent_recurse; parent_recurse = parent_recurse->parent) {
+               if (parent_recurse == parent) {
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
 void nodeAttachNode(bNode *node, bNode *parent)
 {
        float locx, locy;
+
+       BLI_assert(parent->type == NODE_FRAME);
+       BLI_assert(nodeAttachNodeCheck(parent, node) == FALSE);
+
        nodeToView(node, 0.0f, 0.0f, &locx, &locy);
        
        node->parent = parent;
@@ -607,6 +623,9 @@ void nodeDetachNode(struct bNode *node)
        float locx, locy;
        
        if (node->parent) {
+
+               BLI_assert(node->parent->type == NODE_FRAME);
+
                /* transform to view space */
                nodeToView(node, 0.0f, 0.0f, &locx, &locy);
                node->locx = locx;
index 9f6d6d0..de882bd 100644 (file)
@@ -996,9 +996,7 @@ static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode, bN
        float alpha;
        
        /* skip if out of view */
-       if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax ||
-           node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) {
-               
+       if (BLI_rctf_isect(&node->totr, &ar->v2d.cur, NULL) == FALSE) {
                uiEndBlock(C, node->block);
                node->block = NULL;
                return;
index c46c73c..ed52a14 100644 (file)
@@ -681,9 +681,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
                nodeShaderSynchronizeID(node, 0);
        
        /* skip if out of view */
-       if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax ||
-           node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax)
-       {
+       if (BLI_rctf_isect(&node->totr, &ar->v2d.cur, NULL) == FALSE) {
                uiEndBlock(C, node->block);
                node->block = NULL;
                return;
index 85ad590..0af0485 100644 (file)
@@ -762,7 +762,7 @@ static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **r
 /* ************************** Node generic ************** */
 
 /* is rct in visible part of node? */
-static bNode *visible_node(SpaceNode *snode, rctf *rct)
+static bNode *visible_node(SpaceNode *snode, const rctf *rct)
 {
        bNode *node;
        
index 5c59555..d82118f 100644 (file)
@@ -1147,17 +1147,26 @@ static int node_attach_exec(bContext *C, wmOperator *UNUSED(op))
                for (node = ntree->nodes.last; node; node = node->prev) {
                        if (node->flag & NODE_SELECT) {
                                if (node->parent == NULL) {
-                                       /* attach all unparented nodes */
-                                       nodeAttachNode(node, frame);
+                                       /* disallow moving a parent into its child */
+                                       if (nodeAttachNodeCheck(frame, node) == FALSE) {
+                                               /* attach all unparented nodes */
+                                               nodeAttachNode(node, frame);
+                                       }
                                }
                                else {
                                        /* attach nodes which share parent with the frame */
-                                       for (parent = frame->parent; parent; parent = parent->parent)
-                                               if (parent == node->parent)
+                                       for (parent = frame->parent; parent; parent = parent->parent) {
+                                               if (parent == node->parent) {
                                                        break;
+                                               }
+                                       }
+
                                        if (parent) {
-                                               nodeDetachNode(node);
-                                               nodeAttachNode(node, frame);
+                                               /* disallow moving a parent into its child */
+                                               if (nodeAttachNodeCheck(frame, node) == FALSE) {
+                                                       nodeDetachNode(node);
+                                                       nodeAttachNode(node, frame);
+                                               }
                                        }
                                }
                        }
index 3ab5bf7..1585fb1 100644 (file)
@@ -666,7 +666,7 @@ int initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, struc
 void postTrans (struct bContext *C, TransInfo *t);
 void resetTransRestrictions(TransInfo *t);
 
-void drawLine(TransInfo *t, float *center, float *dir, char axis, short options);
+void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis, short options);
 
 void drawNonPropEdge(const struct bContext *C, TransInfo *t);
 
index 43de0f2..8e73fb8 100644 (file)
@@ -923,7 +923,7 @@ void recalcData(TransInfo *t)
        }
 }
 
-void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
+void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis, short options)
 {
        float v1[3], v2[3], v3[3];
        unsigned char col[3], col2[3];
@@ -1017,15 +1017,10 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
        t->total            = 0;
        
        t->val = 0.0f;
-       
-       t->vec[0]           =
-           t->vec[1]       =
-               t->vec[2]       = 0.0f;
 
-       t->center[0]        =
-           t->center[1]    =
-               t->center[2]    = 0.0f;
-       
+       zero_v3(t->vec);
+       zero_v3(t->center);
+
        unit_m3(t->mat);
        
        /* if there's an event, we're modal */