mobius-looper / mobius

Other
19 stars 4 forks source link

Gig Performer: Using Reset in script cancels the rest of the script #5

Closed cllunsford closed 9 months ago

cllunsford commented 9 months ago

I've come across a bug when using this build in Gig Performer(doesn't occur in Reaper or Cubase) First, using any type of the Reset (global or track) commands in a script cancels the rest of the script. This only occurs in Gig Performer.

For instance, if I run a script that resets the track and then records on that same track, the script will reset the track and then..nothing. No script messages on screen either once the scripted reset occurs.

cllunsford commented 9 months ago

Reproduced with Gig Performer 4.5.8 and mobius v2.5.1-rc.1

Simple script:

!name Test

Message This is before the reset!
Reset
Message This is after the reset!

If you start Record on track and run script, the track will reset, but the last Message will not be shown. If you remove the Reset then the last message will be shown.

In standalone Mobius, the same script will reset the track and display the "after reset" message.

cllunsford commented 9 months ago

Grabbed debug output from plugin while the script was executing. Key section:

00000184    58.45568466 [22620] 0 0: Mobius: runScript Test 
00000185    58.45578766 [22620] 0 0: Mobius: Starting script thread     
00000186    58.45584106 [22620] 0 0: Script 1:Test: message This is before the reset!   
00000187    58.45593643 [22620] 0 0: Script 1:Test: Reset   
00000188    58.45598602 [22620] 101 134880: Function Reset down 
00000189    58.45608902 [22620] 0 0: Mobius: Script thread 1:Test: canceling    
00000190    58.45614243 [22620] ERROR: 0 0: Script: Script was reset during execution!  
00000191    58.45623016 [22620] 0 0: Mobius: Script thread 1:Test: ending   

script-reset.log

Compare to debug output on Standalone Mobius when script executes as expected

00000132    8.42098045  [39500] 0 0: Mobius: runScript Test 
00000133    8.42117405  [39500] 0 0: Mobius: Starting script thread     
00000134    8.42131805  [39500] 101 98417: Function Reset down  
00000135    8.42147160  [39500] 0 0: Mobius: Script thread 1:Test: ending   
cllunsford commented 9 months ago

Reviewing source, it looks like the default behavior when a Reset is executed is to cancel all scripts running in the track. A check is made to preserve the script if it's found to be the one that performed the reset (the situation we're encountering here). Need to determine why Mobius is not recognizing the ScriptInterpreter for the script in GP.

https://github.com/mobius-looper/mobius/blob/b6421c9303c0f3b0d9fabb985a114e091aedc12d/src/mobius/Mobius.cpp#L4691-L4714

cllunsford commented 9 months ago

Found the cause of the issue: Action->id is being set as ScriptInterpreter pointer, but truncated to long. This meant that the status check of ScriptInterpreter->id and SourceAction->id no longer matched (action->id was only 32-bits of the full pointer). Replacing Action->id with uintptr_t resolves the issue.