PDA

View Full Version : AvsP crash with global variables


martinfrombern
19th October 2009, 20:23
I created a function and in there are two global variables (clips) defined, because I use them in ScriptClip in the function. However, whenever I call this function two times, AvsP crashes. I tried making only the first call, or only the second and everything works as expected, but when called both all I got is AvsP crash.

function solim(clip clp1, clip clp2, int "x", int "y", int "lwidth", int "lheight")
{
(...)

global strip_down = clp1.crop(x, y, lheight, 2)
global strip_up = replacement.crop(0, lheight-2, -0, 2)

ScriptClip...
(...)
}

(...)

solim(last, denoised, 8)
solim(last, denoised, 59)The problem is definitely in these global variables, because when defining two functions instead of one, renaming second to solim1 and its variables to strip_down1 and strip_up1 and then calling solim and then solim1, everything works fine.

Gavino
20th October 2009, 11:17
I can't say why it crashes, since you haven't shown the contents of the ScriptClip part, but the root of the problem is that each call of the function (and hence each instance of ScriptClip) is using the same global variables - the second function call overwrites these variables before the first ScriptClip uses them.

The solution is to use GRunT's version of ScriptClip, which provides a way of passing values directly into the run-time script, avoiding the need to use global variables.