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

Reply
 
Thread Tools Display Modes
Old 06-17-2019, 07:30 AM   #1
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,313
Default API: GetUserInputs/MB blocks backgroundscripts, when run in defer-cycles

I'm currently building me up some monitoring scripts and Ultraschall-API-functions to work with JSFX and Video-processors as well as relayouting GetUserInputs/MB to some extend and use background-scripts for this heavily.
This works great, but I recently ran into a problem with GetUserInputs: It blocks background-scripts under certain circumstances, but not always.

To be more precise:
1) I run my background-scripts
2) I run a script, that has some defer-cycle in itself
3) This deferred script runs at any point reaper.GetUserInputs or reaper.MB/reaper.ShowMessageBox.

Now here's the problem: if GetUserInputs or MB is run in the first defer-cycle, background-scripts run without a problem.
But as soon, as it enters the second defer-cycle, running GetUserInputs/MB stops background-scripts for the time the dialog is shown.

The next code-snippets show the problem quite good.


First, start this script in the background. It will show the current time in the console and signal, whether it still runs in the background actively.

Code:
-- run this script, which shows constantly the current time in console
-- for signaling, the script still runs

function main()
	reaper.ClearConsole()
	reaper.ShowConsoleMsg(reaper.time_precise())
	reaper.defer(main2)
end

main()

Now run this code in a different script. The first defer-cycle it runs, it will open GetUserInputs with the other script running in the background.
The second defer-cycle, however: it will block further execution of the other script, as long as GetUserInputs is open.

Code:
-- run this script, which shows GetUserInput-dialogs
-- GetUserInputs will let the first script run in the first defer-cycle, but blocks it in the second, third, etc defer-cycle
-- the same happens with reaper.MB and reaper.ShowMessageBox

function main()
	-- the first time GetUserInputs is run, background-scripts keep on running
	-- but in the next defer-cycle, GetUserInputs blocks all execution of background-scripts
	reaper.GetUserInputs("Title", 2, "A,B", "B,C")
	reaper.defer(main)
end

main()
This also happens, when the defer-cycle runs another script(using Main_OnCommand), which opens a GetUserInputs-dialog. In the first defer-cycle, bg-scripts keep running, in the second defer-cycle, bg-scripts pause.

I personally would expect GetUserInputs/MB to always keep background-scripts running, never blocking them. Like the behavior in the first defer-cycle.
The problem with the current behavior is, that anything monitoring in the background can't be done reliably that way anymore(without extreme hacking and massive buffering of data, if possible at all).
So I either never use GetUserInputs/MB anymore or can't keep monitoring all the times without risking losing data/eating up resources for caching potentially massive amounts of data in gmems which would be a nightmare and too hacky to do.
It also prevents me from relayouting GetUserInputs in the background, making things like longer captions, inputfields moved underneath the caption for resizing them to full window-width, getting rid of the comma-problems in (default-)retvals and captions, etc impossible to do in a stable way.

If you could lift up this limitation(or bug?), this would open tons of possibilities for me.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 07-06-2019, 03:28 AM   #2
Dafarkias
Human being with feelings
 
Dafarkias's Avatar
 
Join Date: Feb 2019
Location: England
Posts: 105
Default

Hey Mespotine!

Sorry for commenting on this post...

Have you encountered other strange behavior with GetUserInput in defer loops, by chance?

For example, I'm trying to have a script that where when a user presses the 'c' key it triggers a reaper.MB and a reaper.GetUserInput.

Problem: even though I put limitations in an 'if' statement, both the MB and GetUserInput message/user-prompt are triggered multiple times.

[code snippet]
Code:
  if gfx.getchar(99) == 1 and reaper.time_precise() > update[1] + 1
  then
    reaper.MB( "Enter '0' to reset all selected item(s) colors to their track color.\n\n"..
    "Enter '1' to change the color of all selected item(s) of an identical source.\n\n"..
    "Enter '2' to change the color of all selected item(s) of an identical source with matching source start-time(s).", "[message]", 0 )
    local _, dummy = reaper.GetUserInputs( "[user input]", 1, "", "0/1/2")
    update[1] = reaper.time_precise() 
  end
For the life of me I can't figure out why the portion of code is being triggered multiple times when one of the stipulations I included in the 'if' statement is that the 'if' statement's contents may only be activated at most 1 time a second.

[Edit 7/6/19]

I actually think now, after a little more consideration that the issue you state in this post is definitely somewhat related to the problem I'm experiencing. It seems as if when reaper.GetUserInput idles the defer process, and then brings it back 'online' that somehow multiple threads are created in this process, which effectively 'simultaneously' trigger the gfx.char 'if' statement.

[Edit 7/6/19]

Figured out a solution for my issue of multi-threading, it was actually pretty simple. Essentially I had to put the 'if' statement limitation return value outside of the 'if' statement structure. Very odd.

Last edited by Dafarkias; 07-06-2019 at 07:16 AM.
Dafarkias is offline   Reply With Quote
Old 07-12-2019, 09:26 AM   #3
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,313
Default

Could be. Took me a while to understand that problem in the first place, but didn't look further for more side-effects this actually has.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine 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 01:13 PM.


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