Execution order with [js] mixed up / depending on if manual or metro bang

Mar 30, 2012 at 8:51pm

Execution order with [js] mixed up / depending on if manual or metro bang

I am observing a weird delay issue involving a javascript object. I wonder if its due to a setting on my computer / some maxmsp settings, or if its a bug in the system. I would be grateful if someone could copy the code below and verify if it behaves the same way for them.

I use a js-object, and for some reason the execution of the javascript seems to be delayed depending on if i trigger the execution with a manual bang or a bang coming from a metro object. And i can’t explain why …

– Pasted Max Patch, click to expand. –
Attachments:
  1. jsweird.maxpat
#62686
Mar 31, 2012 at 2:03am

This is probably relevant:
Controlling a Function’s Thread of Execution
…most notably the line that reads,
“By default, the js object executes all Javascript code in the low-priority thread. In particular, if it finds itself running in the high-priority thread, it will defer execution of whatever it was supposed to do to the low-priority thread.”

#226388
Mar 31, 2012 at 5:54am

Hello,

have a look on immediate method.

If i remember correctly something like :

msg_int.immediate = 1;

oops … have a look on previous post link ;-)

#226389
Mar 31, 2012 at 2:39pm

This sounds like it should be the solution!

Sadly, including

msg_int.immediate = 1;

into the javascript keeps crashing Max. When i hit the bang manually, all is fine. But it crashes when i try to activate the toggle button of the metro object.

#226390
Mar 31, 2012 at 4:04pm

Seems to behave differently on Windows and OSX.
According to different posts on this forum.

#226391
Mar 31, 2012 at 4:04pm

The immediate method is deprecated in Max6.

Calls to it in JS code will be ignored. Sorry about the confusion, we’ll tidy up the docs.

It shouldn’t crash either, we’ll have a look.

-A

#226392
Mar 31, 2012 at 4:07pm

Still on Max 5.1.4 (on Windows 7).

#226393
Mar 31, 2012 at 4:25pm

@evsc

Yes, unfortunately you may be looking at one of the reasons why we deprecated it.
JS in Max5 had a multi threaded implementation which had problems, and when we upgraded JS for Max6 it was deemed more trouble than it was worth.JS in Max 6 is single threaded.

Your patch behaves exactly as it should, both with Overdrive on and off. JS always executes in the low priority thread. Ui interactions also always occur in the low priority thread, which is why you see a difference between the button press and the metro with Overdrive on.

Cheers

Andrew

#226394

You must be logged in to reply to this topic.