Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 12-11-2018, 09:29 PM   #1
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 2,236
Default Strange JSFX hang... (Can anyone reproduce?) (FIXED)

Had a strange busy-cycle hang happening with a project. After many many hours I have narrowed it down to this absurd demo code. It's bizarrely sensitive to any changes; as far as I've found every line has to be present, and even changes that seem meaningless (e.g. changing the test condition for the first while loop to remove the "-1", or removing pointless assignments, etc.) will make the hang go away and everything work normally.

So I'm thinking this is a bug, unless someone enlightens me as to what is going wrong?

Again, this is nonsensical code just to show the issue, so don't ask why I'm doing some pointless thing. :-) AFAICT, there should be no busy hangs in this code, even though it's crazy.

To reproduce, open a fresh profile [edit: by which I of course mean a new reaper install], make a track, throw it on there. Then start the transport and click around in the arrange window a bunch. Sometimes I need to start/stop a few times, etc. It usually kicks in in 3-10 seconds. The GUI hangs and the program is unresponsive.

This happens in Linux (5.96 and 5.963) and in Windows (5.95).

Code:
slider1:25<10,300,1>

@slider

slidervar=floor((slider1/1000)*srate+.5);

@gfx

function funcA()
(
  index=0;
  while (index+slidervar-1<0)
  (
    result+=1;
    index+=slidervar;
  );
  total=result;

  result=0;
);

function funcB()
(
  counter=total;

  while(counter >= 0)
  (
    idx=0;
    while(idx <= total-counter)
    (
      idx+=1;
    );
 
    counter-=1;
  );
);

funcA();
funcB();

Last edited by clepsydrae; 12-11-2018 at 10:54 PM.
clepsydrae is online now   Reply With Quote
Old 12-11-2018, 11:07 PM   #2
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 6,333
Default

The @gfx code is called in (quite) regularly timed intervals. Hence when the runtime of such code is greater that the interval time, weird things are bound to happen.

-Michael
__________________
www.boa-sorte.de
mschnell is offline   Reply With Quote
Old 12-11-2018, 11:21 PM   #3
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 2,236
Default

Quote:
Originally Posted by mschnell View Post
The @gfx code is called in (quite) regularly timed intervals. Hence when the runtime of such code is greater that the interval time, weird things are bound to happen.
Are you saying that the @gfx is potentially entered by multiple threads at once?
clepsydrae is online now   Reply With Quote
Old 12-12-2018, 02:09 AM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 6,333
Default

No, AFAIK, @gfx only uses the GUI thread, and there is only one GUI thread (Usually the so called main thread of the program). While @sample and @block use the thread that is assigned to the track, which always is a different thread than the GUI thread.

But if the execution of @gfx takes longer than the interval @gfx is called by Reaper, there is no time left for other stuff to be done in the GUI thread. I don't know how Reaper schedules the multiple activities of the GUI thread (Reaper GUI, every single plugin, ...), but none of these is allowed to take a long time.

A recent version of the Kontakt featured a bug that it's GUI entered a closed loop when the user performs a certain kind of action. This hangs the Reaper GUI. No Mouse activity possible any more. Fortunately I found that Kontakt leaves that loop (or Reaper forces Kontakt to do so) when hitting the Esc key.

So a JSFX should never do more than a few loop cycles in @gfx. If you really need to do a long loop, you need to leave that loop rather soon and re-enter that activity with the next call to @gfx, and display the results only when the task is done. This might result in a jumpy GUI look of that JSFX, but will prevent it from harming other GUI activity.

-Michael
__________________
www.boa-sorte.de
mschnell is offline   Reply With Quote
Old 12-12-2018, 10:42 AM   #5
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 2,236
Default

Thanks -- I understand that @gfx can hang reaper -- but I think if you look at the code you will see that it should never do that -- none of the loops in those two functions should ever execute anything, ever. It's basically calling two null functions.

And again, if you make the slightest change to the code, it runs fine and never hangs.

E.g. the first while is "while (index+slidervar-1<0)". If you change that to "while (index+slidervar<0)", it never hangs.

slidervar is 1103. If instead of "slidervar=floor((slider1/1000)*srate+.5);" you say "slidervar=1103;", it never hangs.

So the "it should never ever do anything" plus "it's weirdly sensitive" make me think a bug (or PEBKAC) is afoot.

If there was a multithreading bug between @slider and @gfx, where @gfx was sometimes seeing sliderval as 0, that might explain it. I'd still scratch my head a little about why it's so sensitive to any code changes in funcB, but perhaps some kind of pileup effect of semi-busy @gfx calls is in play.

But JSFX/EEL2 has confused me 100 times and then I learn something new about its nuances, hence my query here about something I'm overlooking.
clepsydrae is online now   Reply With Quote
Old 12-12-2018, 11:08 AM   #6
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Germany
Posts: 6,333
Default

Quote:
Originally Posted by clepsydrae View Post
E.g. the first while is "while (index+slidervar-1<0)". If you change that to "while (index+slidervar<0)", it never hangs.
Seemingly, in eel, "<" binds stronger than "-". Hence
while(index+slidervar-1<0) means
while(index+slidervar-(1<0)) and as (1<0) is false and false is 0 this is
while(index+slidervar) and this is the same as
while((index+slidervar)!=0) and this close to always is true.

I suppose what you mean is
while((index+slidervar-1)<0) .

-Michael
__________________
www.boa-sorte.de
mschnell is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.