Jump to content

Scripter can crash Logic Pro now


Dewdman42
Go to solution Solved by Dewdman42,

Recommended Posts

Well I finally found a way to crash Scripter, I think this is a bug with safari frankly, and not sure when it was introduced, I haven't been scripting a lot lately so it could have been around a while by now.  but basically if you try to call Trace with an argument of an array, including in a stringified version, LogicPro completely crashes.    This is with LogicPro 10.7.9 and MacOS 12.7.2

Either one of the following two lines will crash LogicPro as an example:

Trace(MIDI._ccNames);

Trace(JSON.stringify(MIDI._ccNames));

I don't have a lot of time to investigate this further, but just wanted to report it and see if anyone else gets the problem with other versions of LogicPro and/or MacOs.   The MacOS version may be a factor since Scripter is using built in Javascript at the OS level...

 

Edited by Dewdman42
Link to comment
Share on other sites

Good to know about it working from inside HandleMIDI but not outside..which is still strange behavior frankly...but anyway good to know..

Let me give you something to work around the non-crashing error that is normal...  

Put this bit of code at the top of the script

var console = {
   maxFlush: 20,
   b:[],
   log: function(msg) {this.b.push(msg)},
   flush: function() {
       var i=0;
       while(i<=this.maxFlush && this.b.length>0) {
           Trace(this.b.shift());
           i++;
       }
   }
};
function Idle() {
   console.flush();
}

And then in your test script below that, rather then using the Trace function use console.log like this:

console.log(MIDI._ccNames);

That will buffer the tracing.  The error you got before has more to do with LogicPro not wanting to see too much stuff sent to the console during one Trace command or else it will cause Scripter to hiccup.  By using the buffered logging it gets around that particular little annoyance.

mainly just want to find out how or why it crashes.

 

 

Edited by Dewdman42
Link to comment
Share on other sites

My thoughts at the moment are that the Trace function has become problematic if you try to trace a string larger then a certain size...it will blow up Logic Pro.  I am going to try to see if I can figure out what that size limit is.  Not very big honestly the totally stringified size of MIDI._ccNames is really not that large.. but anyway I will try to see what I can figure out.

  • Like 1
Link to comment
Share on other sites

Getting closer....  Ran this little test script, it handled tracing up to 1021, then started complaining and eventually crashed when it got to around 1070, I couldn't see because it crashed before I could see exactly, but I will try to pin point.

bottom line...  Trace can handle probably max 1024, might might be a few characters less then that...

IMG_0137.thumb.jpeg.df8fff52a3314479522fb1e61be29413.jpeg

As far as I'm concerned this is a rather bad bug, Scripter Trace should not be able to crash logicpro like this..  Not sure which version of LPX this started happening, so if anyone has older MacOs and/or older LogicPro to try it with, perhaps we can figure out when and where they introduced this bug, which is likely inside the javascript engine of MacOs...in other words the bug is probably not in logicPro itself, but rather in MacOS version.

I'll try to pinpoint the exact string size limit for error and for crash

 

Link to comment
Share on other sites

In case anyone wants to try to replicate this bug, here is a test script.  Load it, hit runscript button and watch the scripter console, it will take 2 seconds per iteration, so you'll have to watch it a minute or two...  basically at string size of 1022 it starts complaining about the string size, and at 1071 it blows up and crashes LogicPro.

I will report this bug to Apple, and anyone else can too in order to boost priority, I would also appreciate to hear what happens with an older version of MacOS and LogicPro.

I think you can replicate the bug easily just by trying to Trace any string larger than 1070 characters long.

I will also later provide a work around, buffered logging that will make sure it never calls trace with more than 1020 characters.

function Idle() {
   testTrace();
}

var lastTime = new Date().getTime();
var buffer = "";
var size = 1000;

function testTrace() {
   var newTime = new Date().getTime();
   if( newTime > (lastTime + 2000)) {
       lastTime = newTime;
       buffer = "";
       for(let i=0; i<size; i++) {
           buffer = buffer + "A";
       }
       Trace("Testing "+size);
       Trace(buffer);
       size++
   }
}

 

  • Like 1
Link to comment
Share on other sites

  • Solution

Ok here is a work around for this Trace bug.  Use this console object to buffer the logging.  This will break up long strings over 1000 chars onto separate Trace lines and avoid the bug from crashing LogicPro.  Because its buffered you will also not get the annoying message where Scripter doesn't actually Trace what you asked it to.  Put this little tid bit of code into your Script and then instead of calling Trace(), call console.log()


var console = {
   maxFlush: 20,
   maxLen:   1000,
   b:[],
   log: function(msg) {this.b.push(msg)},
   flush: function() {
       var i=0;
       while(i<=this.maxFlush && this.b.length>0) {
           var line=this.b.shift();
           if(typeof line != "string") {
               line = line.toString();
           }
           var tl = line.length;
           var p = 0;
           var sub=line.substr(p,this.maxLen);
           Trace(sub);
           p += this.maxLen;
           while(p < tl) {
               sub = line.substr(p,this.maxLen);
               Trace("..." + sub);
               p += this.maxLen;
           }
           i++;
       }
   }
};
function Idle() {
   console.flush();
}

 

Anyway, here is a test script, that will output 5000 char string to the console to see it work.  I also have it output the MIDI. _ccNames array.  If you uncomment the last line with the Trace() function call it will crash LogicPro.


var console = {
   maxFlush: 20,
   maxLen:   1000,
   b:[],
   log: function(msg) {this.b.push(msg)},
   flush: function() {
       var i=0;
       while(i<=this.maxFlush && this.b.length>0) {
           var line=this.b.shift();
           if(typeof line != "string") {
               line = line.toString();
           }
           var tl = line.length;
           var p = 0;
           var sub=line.substr(p,this.maxLen);
           Trace(sub);
           p += this.maxLen;
           while(p < tl) {
               sub = line.substr(p,this.maxLen);
               Trace("..." + sub);
               p += this.maxLen;
           }
           i++;
       }
   }
};
function Idle() {
   console.flush();
}

/*****************************
 * Create a test buffer with
 * 5000 chars
 *****************************/
 
var pattern = "1234567890";
var lookup = "";
for(let i=0; i<500; i++) {
    lookup = lookup + pattern;
}

/***********************************
 * log it with buffered console.log
 ***********************************/
 
 console.log(lookup);
 console.log(MIDI._ccNames);
 
 // Uncomment this line to crash logic Pro
 // Trace(lookup);
Evaluating MIDI-processing script...
Script evaluated successfully!
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
...1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
...1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
...1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
...1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Bank MSB,Modulation,Breath,Ctrl 3,Foot Control,Portamento,Data MSB,Volume,Balance,Ctrl 9,Pan,Expression,Effect #1 MSB,Effect #2 MSB,Ctrl 14,Ctrl 15,General #1,General #2,General #3,General #4,Ctrl 20,Ctrl 21,Ctrl 22,Ctrl 23,Ctrl 24,Ctrl 25,Ctrl 26,Ctrl 27,Ctrl 28,Ctrl 29,Ctrl 30,Ctrl 31,Bank LSB,#01 LSB,#02 LSB,#03 LSB,#04 LSB,#05 LSB,#06 LSB,#07 LSB,#08 LSB,#09 LSB,#10 LSB,#11 LSB,Effect #1 LSB,Effect #2 LSB,#14 LSB,#15 LSB,#16 LSB,#17 LSB,#18 LSB,#19 LSB,#20 LSB,#21 LSB,#22 LSB,#23 LSB,#24 LSB,#25 LSB,#26 LSB,#27 LSB,#28 LSB,#29 LSB,#30 LSB,#31 LSB,Sustain,Portamento,Sostenuto,Soft Pedal,Legato,Hold2,Sound Var,Resonance,Release Time,Attack Time,Brightness,Decay Time,Vibrato Rate,Vibrato Depth,Vibrato Delay,Ctrl 79,Decay,HPF Frequ,General #7,General #8,Portamento Ctl,Ctrl 85,Ctrl 86,Ctrl 87,Ctrl 88,Ctrl 89,Ctrl 90,Reverb,Tremolo,Chorus Depth,Detune/Var.,Phaser,Data increm.,Data decrem.,Non-Reg. LSB,Non-Reg. MSB,Reg.Par. LSB,Reg.Par. MSB,Ctrl 102,Ctrl 103,Ctrl 104,Ctrl 105,Ctrl 106,Ctr
...l 107,Ctrl 108,Ctrl 109,Ctrl 110,Ctrl 111,Ctrl 112,Ctrl 113,Ctrl 114,Ctrl 115,Ctrl 116,Ctrl 117,Ctrl 118,Ctrl 119,All Sound Off,Reset Ctrls.,Local Control,All Notes Off,Omni Mode Off,Omni Mode  On,Mono Mode On,Poly Mode On
>

 

I encourage others to report this bug to Apple.  Scripter should be completely sandboxed and unable to crash Logic Pro.

 

Edited by Dewdman42
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...