diff options
author | Matt Ebb <matt@mke3.net> | 2011-04-18 02:47:23 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2011-04-18 02:47:23 +0400 |
commit | 8b2a3c250a7faf59c7f8549960737ef40f4ff29c (patch) | |
tree | 4d5956ccb0779a6b2436064c59452479e9ed4170 /source/blender/nodes/intern/CMP_nodes | |
parent | f261a22263414520d7a6ad6e0d674f828b0c0373 (diff) |
Fix [#26896] Displace Node crashes Blender when connected to Z-Buffer
Clamped the maximum displacement distance to 4 x the input image dimensions - prevents hanging when vary large values are mistakenly plugged in, such as Z buffers,
Diffstat (limited to 'source/blender/nodes/intern/CMP_nodes')
-rw-r--r-- | source/blender/nodes/intern/CMP_nodes/CMP_displace.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_displace.c b/source/blender/nodes/intern/CMP_nodes/CMP_displace.c index d52a47993d2..9139edf8560 100644 --- a/source/blender/nodes/intern/CMP_nodes/CMP_displace.c +++ b/source/blender/nodes/intern/CMP_nodes/CMP_displace.c @@ -53,7 +53,7 @@ static bNodeSocketType cmp_node_displace_out[]= { * in order to take effect */ #define DISPLACE_EPSILON 0.01 -static void do_displace(CompBuf *stackbuf, CompBuf *cbuf, CompBuf *vecbuf, float *UNUSED(veccol), CompBuf *xbuf, CompBuf *ybuf, float *xscale, float *yscale) +static void do_displace(bNode *node, CompBuf *stackbuf, CompBuf *cbuf, CompBuf *vecbuf, float *UNUSED(veccol), CompBuf *xbuf, CompBuf *ybuf, float *xscale, float *yscale) { ImBuf *ibuf; int x, y; @@ -83,6 +83,10 @@ static void do_displace(CompBuf *stackbuf, CompBuf *cbuf, CompBuf *vecbuf, float else ys = yscale[0]; + /* clamp x and y displacement to triple image resolution - + * to prevent hangs from huge values mistakenly plugged in eg. z buffers */ + CLAMP(xs, -stackbuf->x*4, stackbuf->x*4); + CLAMP(ys, -stackbuf->y*4, stackbuf->y*4); p_dx = vec[0] * xs; p_dy = vec[1] * ys; @@ -114,7 +118,11 @@ static void do_displace(CompBuf *stackbuf, CompBuf *cbuf, CompBuf *vecbuf, float ibuf_sample(ibuf, u, v, dxt, dyt, col); qd_setPixel(stackbuf, x, y, col); + + if(node->exec & NODE_BREAK) break; } + + if(node->exec & NODE_BREAK) break; } IMB_freeImBuf(ibuf); @@ -145,7 +153,7 @@ static void do_displace(CompBuf *stackbuf, CompBuf *cbuf, CompBuf *vecbuf, float } -static void node_composit_exec_displace(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out) +static void node_composit_exec_displace(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) { if(out[0]->hasoutput==0) return; @@ -164,7 +172,7 @@ static void node_composit_exec_displace(void *UNUSED(data), bNode *UNUSED(node), stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* allocs */ - do_displace(stackbuf, cbuf, vecbuf, in[1]->vec, xbuf, ybuf, in[2]->vec, in[3]->vec); + do_displace(node, stackbuf, cbuf, vecbuf, in[1]->vec, xbuf, ybuf, in[2]->vec, in[3]->vec); out[0]->data= stackbuf; |