forked from bartvdbraak/blender
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,
This commit is contained in:
parent
f261a22263
commit
8b2a3c250a
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user