refactor node highlight code. New implementation will not write to

uninitialized memory. it happened when you delete a node that was being
executed. in the compostor
This commit is contained in:
Jeroen Bakker 2012-07-10 12:23:49 +00:00
parent 5cc0e5f751
commit dc65a26bf6
7 changed files with 61 additions and 12 deletions

@ -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

@ -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
}

@ -31,6 +31,7 @@ set(INC
../../nodes
../../render/extern/include
../../windowmanager
../../compositor
../../../../intern/guardedalloc
../../../../intern/opennl/extern
)

@ -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 = []

@ -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

@ -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 */

@ -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)