View Full Version : Avisynth crashes when trying to use a maxmulti func


feisty2
17th August 2014, 12:20
I'm cooking up a simple function "MaxMulti" for motion compensated temporal limit at any time radius

Function MaxMulti (clip input, clip "start", int "tr")
{
tr = Default (tr, 3)
start = Default (start, Mt_logic (input.SelectEvery (tr*2+1, 0), input.SelectEvery (tr*2+1, 1), "max", y=3, u=3, v=3))

a = 2
max = Mt_logic (start, input.SelectEvery (tr*2+1, a), "max", y=3, u=3, v=3)
a = a+1

output = (a == tr*2+1) ? max : input.MaxMulti (start=max, tr=tr)

return output
}

but when I run the script, avisynth just crashes without a warning, so I guess the error should be quiet serious, but I don't get it, is there anything wrong with the script?

Gavino
17th August 2014, 14:22
Function MaxMulti (clip input, clip "start", int "tr")
{ ...

a = 2
max = Mt_logic (start, input.SelectEvery (tr*2+1, a), "max", y=3, u=3, v=3)
a = a+1

output = (a == tr*2+1) ? max : input.MaxMulti (start=max, tr=tr)
...
Recursive stack overflow.
Since a is always 3 at this point, recursion will continue forever unless tr is 1.
Perhaps you meant to use tr=tr-1 in the recursive call?
Or maybe a needs to be passed as a parameter so it can vary on each call?

feisty2
17th August 2014, 14:56
Thank U, Gavino!
I finally noticed that "a" error with your tips
I corrected the code

Function MaxMulti (clip input, clip "start", int "a", int "tr")
{
tr = Default (tr, 3)
start = Default (start, Mt_logic (input.SelectEvery (tr*2+1, 0), input.SelectEvery (tr*2+1, 1), "max", y=3, u=3, v=3))
a = Default (a, 2)

max = Mt_logic (start, input.SelectEvery (tr*2+1, a), "max", y=3, u=3, v=3)
a = a+1

output = (a == tr*2+1) ? max : input.MaxMulti (start=max, tr=tr, a=a)

return output
}

seems working now :)