refactor node highlight code. New implementation will not write to
authorJeroen Bakker <j.bakker@atmind.nl>
Tue, 10 Jul 2012 12:23:49 +0000 (12:23 +0000)
committerJeroen Bakker <j.bakker@atmind.nl>
Tue, 10 Jul 2012 12:23:49 +0000 (12:23 +0000)
uninitialized memory. it happened when you delete a node that was being
executed. in the compostor

source/blender/compositor/COM_compositor.h
source/blender/compositor/intern/COM_WorkScheduler.cpp
source/blender/editors/space_node/CMakeLists.txt
source/blender/editors/space_node/SConscript
source/blender/editors/space_node/node_draw.c
source/blender/makesdna/DNA_node_types.h
source/blender/nodes/composite/node_composite_tree.c

index 86390e5650aadb3201ff8c18c5ebd5eaee14d097..60bceba57656f576a6390af5f65c416cca2bb914 100644 (file)
@@ -299,6 +299,19 @@ extern "C" {
  */
 void COM_execute(RenderData* rd, bNodeTree *editingtree, int rendering);
 
+/**
+ * @brief Return a list of highlighted bnodes pointers.
+ * @return 
+ */
+void COM_startReadHighlights();
+
+/**
+ * @brief check if a bnode is highlighted
+ * @param bnode
+ * @return 
+ */
+int COM_isHighlightedbNode(bNode* bnode);
+
 #ifdef __cplusplus
 }
 #endif
index 120b4d6d0f275ea378e1ea03ae954017e650d6c8..c7544be1bb4e8b69059970be4ac95c2665289123 100644 (file)
@@ -66,6 +66,12 @@ static bool g_openclActive = false;
 #endif
 #endif
 
+#define MAX_HIGHLIGHT 8
+extern "C" {
+int g_highlightIndex;
+void ** g_highlightedNodes;
+void ** g_highlightedNodesRead;
+
 #define HIGHLIGHT(wp) \
 { \
        ExecutionGroup* group = wp->getExecutionGroup(); \
@@ -77,14 +83,38 @@ static bool g_openclActive = false;
                        bNode *node = complexOperation->getbNode(); \
                        if (node) { \
                                if (node->original) { \
-                                       node->original->highlight = 1;\
-                               } else {\
-                                       node->highlight = 1; \
+                                       node = node->original;\
+                               }\
+                               if (g_highlightIndex < MAX_HIGHLIGHT) {\
+                                       g_highlightedNodes[g_highlightIndex++] = node;\
                                }\
                        } \
                } \
        } \
 }
+void COM_startReadHighlights() {
+       if (g_highlightedNodesRead) {
+               delete g_highlightedNodesRead;
+       }
+       
+       g_highlightedNodesRead = g_highlightedNodes;
+       g_highlightedNodes = new void*[MAX_HIGHLIGHT];
+       g_highlightIndex = 0;
+       for (int i = 0 ; i < MAX_HIGHLIGHT; i++) {
+               g_highlightedNodes[i] = 0;
+       }
+}
+
+int COM_isHighlightedbNode(bNode* bnode) {
+       if (!g_highlightedNodesRead) return false;
+       for (int i = 0 ; i < MAX_HIGHLIGHT; i++) {
+               void* p = g_highlightedNodesRead[i];
+               if (!p) return false;
+               if (p == bnode) return true;
+       }
+       return false;
+}
+} // end extern "C"
 
 #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
 void *WorkScheduler::thread_execute_cpu(void *data)
@@ -219,6 +249,9 @@ extern void clContextError(const char *errinfo, const void *private_info, size_t
 
 void WorkScheduler::initialize()
 {
+       g_highlightedNodesRead = 0;
+       g_highlightedNodes = 0;
+       COM_startReadHighlights();
 #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
        int numberOfCPUThreads = BLI_system_thread_count();
 
@@ -313,3 +346,4 @@ void WorkScheduler::deinitialize()
 #endif
 #endif
 }
+
index 8c3397b9ddde669bc30a573c0ec213d9f38acc0a..9c48ce4034d71c712ef064974db0c637f2363b1a 100644 (file)
@@ -31,6 +31,7 @@ set(INC
        ../../nodes
        ../../render/extern/include
        ../../windowmanager
+       ../../compositor
        ../../../../intern/guardedalloc
        ../../../../intern/opennl/extern
 )
index 2dee750f8c09c4032dc5630c7b6b45f239826379..4c6e94484e4f88fde468a5c2e066bff0fb18b401 100644 (file)
@@ -4,7 +4,7 @@ Import ('env')
 sources = env.Glob('*.c')
 
 incs = '../include ../../blenfont ../../blenlib ../../blenkernel ../../makesdna ../../makesrna ../../imbuf'
-incs += ' ../../nodes ../../render/extern/include ../../blenloader ../../gpu'
+incs += ' ../../nodes ../../render/extern/include ../../blenloader ../../gpu ../../compositor'
 incs += ' ../../windowmanager #intern/guardedalloc #extern/glew/include'
 defs = []
 cf = []
index 89a4d92b29512c6c85443d50a9c23cce94fc436e..7be76bd788418cf84b27500f879ce875b1e2c081 100644 (file)
@@ -80,6 +80,7 @@
 #include "intern/node_util.h"
 
 #include "node_intern.h"
+#include "COM_compositor.h"
 
 /* width of socket columns in group display */
 #define NODE_GROUP_FRAME  120
@@ -726,9 +727,8 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
                UI_ThemeColorBlend(color_id, TH_REDALERT, 0.5f);
 
        if (ntree->type == NTREE_COMPOSIT && (snode->flag & SNODE_SHOW_HIGHLIGHT)) {
-               if (node->highlight) {
+               if (COM_isHighlightedbNode(node)) {
                        UI_ThemeColorBlend(color_id, TH_ACTIVE, 0.5f);
-                       node->highlight = 0;
                }
        }
        uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
@@ -893,9 +893,8 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b
                UI_ThemeColorBlend(color_id, TH_REDALERT, 0.5f);
 
        if (ntree->type == NTREE_COMPOSIT && (snode->flag & SNODE_SHOW_HIGHLIGHT)) {
-               if (node->highlight) {
+               if (COM_isHighlightedbNode(node)) {
                        UI_ThemeColorBlend(color_id, TH_ACTIVE, 0.5f);
-                       node->highlight = 0;
                }
        }
        
@@ -1133,6 +1132,7 @@ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d)
        
        if (snode->nodetree) {
                bNode *node;
+               void** highlights = 0;
                
                node_uiblocks_init(C, snode->nodetree);
                
@@ -1145,6 +1145,9 @@ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d)
                }
                
                node_update_nodetree(C, snode->nodetree, 0.0f, 0.0f);
+               if (snode->nodetree->type == NTREE_COMPOSIT) {
+                       COM_startReadHighlights();
+               } 
                node_draw_nodetree(C, ar, snode, snode->nodetree);
                
                #if 0
index ea894ff7a0dc0bf6addf4bbaeafc1aac2538ebf3..58a6332515e11f82421b5ee3764a8c25d666b316 100644 (file)
@@ -178,9 +178,7 @@ typedef struct bNode {
        char label[64];                 /* custom user-defined label, MAX_NAME */
        short custom1, custom2; /* to be abused for buttons */
        float custom3, custom4;
-       int highlight;                  /* 0 = not highlighted, 1-N = highlighted*/
-       int pad;
-       
+
        short need_exec, exec;  /* need_exec is set as UI execution event, exec is flag during exec */
        void *threaddata;               /* optional extra storage for use in thread (read only then!) */
        rctf totr;                              /* entire boundbox */
index b9acf821efe590879eeb79f17e394c563a9f21f3..43edc06194d1e7badb99c1106e62db5d03c2d0a0 100644 (file)
@@ -61,7 +61,7 @@
 #include "node_composite_util.h"
 
 #ifdef WITH_COMPOSITOR
-#  include "COM_compositor.h"
+       #include "COM_compositor.h"
 #endif
 
 static void foreach_nodetree(Main *main, void *calldata, bNodeTreeCallback func)