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 00bdbbf453777ae0568fa24191bc003d5acf9247..55d9e700efcd5be2d0716dc6af4d5899038d0eae 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 565e2de79f8a8ef1242d99df4a8ad8c41aaef23f..4090b6fe93b06e4b3bc28b1327cd97f4b189331b 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 9f6d6d0170f9b17fa0dc045f0898c85821693350..de882bd3635ea4203a6b97099c466ee7af85b81d 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 c46c73cadb25b75b3454def687e48e59b43df83b..ed52a14ec986078b6bed19c284341448c2647aaf 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 85ad590f772a076578a33d1ea1650a689c562bcb..0af04856522fd447b6f75566248592c4232f7bd6 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 5c59555a0ed1da4d085f6c46d0ad580a61c6d29a..d82118facd1404bb99aa00d804255061ae5fe13d 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 3ab5bf7bbfb226a3504208c2cce3449bc9b0f16a..1585fb1ad6b07f8926ba62c84959b5fc1b9a375e 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 43de0f2b35f2098e698da1ed8414b386b9389dcd..8e73fb8b8cbca033619fd9dfa266adc696f43a4a 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 */