ParameterListener broken in v8?

Tukkelum's icon

Hi all,

i am facing a problem with the ParameterListener in v8, which is driving me nuts.

When I freshly create widgets and bind a parameter listener to it, everything works fine. The callback function gets called and the silent mode (setvalue) is working.

After saving and reloading, the binds are missing which seems reasonably, since they had been created and stored in the v8 script. After binding them again, the nightmare starts. All callbacks seem to be called twice! The silent option is no longer working. I don‘t remember how, but I even managed to break the patch in a way that some callbacks are even called up to four times.

I assume, there must be an orphaned reference to the maxobject from the first binding which magically gets resurrected, after binding the maxobject again. This could explain the erroneous silent behaviour as well, if the resurrected listener would ignore the silent property.

Unfortunately. there seems to be no function to remove all callbacks from a maxobject.

Did someone encounter the same problem and found a solution? After endless hours of trying I‘m really desperate.

Thanks a lot

Tukkelum's icon

Ok, after testing several options, I found out the following: The same phenomenon occurs when using js instead of v8. It even occurs in the standalone version of Max and not only in the max4live version. Every re-binding creates an additional callback, which is consistent at least.

It looks like I can circumvent this problem by sending a compile message to the script before re-binding. This way the old callbacks seem to be removed.

Unfortunately I got this to work in the standalone version of Max only. In max4live something seems to happen during the save process which at least keeps one reference to the original callback.

Don't know if this the intended behavior, if it is a bug or if I am doing something wrong.

Maybe it is helpful for others coming across the same problem.

TFL's icon

I don't know if will actually work or do anything, but you can try to call freepeer() on your MaxobjListener, something like that:

function notifydeleted() {
  my_listener.freepeer();
}

freepeer() isn't documented in the MaxobjListener reference, but it doesn't throws an error either, so maybe it does something!

This put aside, sharing a patch and actual code could also help us see what the problem could be, and/or envision possible solutions more easily.

Tukkelum's icon

Thanks TFL. I will give it a try. I am using a ParameterListener not a MaxobjListener. Have to check whether this works for the ParameterListener too.

I normally post the code, but after hours of useless changes the whole thing became too messy to go public. When I have calmed down, I might post a patch showing the problem.

As I posted, I had a fresh start this morning and it seems to work in the full Max version.

TFL's icon

My bad, I read too quickly. I don't think I ever used ParameterListener, and now I wonder what the difference is between a new ParameterListener("foo", callback) and a new MaxobjListener(this.patcher.getnamed("foo"), callback) beside the fact the second can listen to attributes (not only the objects value) and return also the Maxobj.