OSX. Sketch that hangs

Home Forums Procoding OSX. Sketch that hangs

Tagged: , , ,

This topic contains 14 replies, has 1 voice, and was last updated by  Andy Buchanan 6 years ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #789

    Andy Buchanan

    I have a sketch that hangs the editor – my first one as it goes. Is there a way for me to recover the source from the sketch file? Can I send you the file to figure out the problem?
    Cheers, Andy.

    #790

    Andy Buchanan

    I managed to recover the code from the package. Yay! The block of code that apparently causes the confusion seems to be this – in particular it seems to be the values in the ‘r’ comparisons that throw it. Weird.

    (function _empty(){
    for ( var y=0; y<_h ; ++y ){
    for ( var x=0; x 0.98 ) { targetConnections=4; }
    else if ( r > 0.90 ) { targetConnections=3; }
    else if ( r > 0.8 ) { targetConnections=2; }
    else { targetConnections=1; }

    while ( numConnections < targetConnections )
    {
    _ConnectOne( x, y, _random( 3.5 ) );
    numConnections = _ConnectionCount(x, y);
    }

    }
    }
    }());

    #791

    Andy Buchanan

    Try again!

    (function _empty(){
    for ( var y=0; y<_h ; ++y ){
    for ( var x=0; x 0.98 ) { targetConnections=4; }
    else if ( r > 0.90 ) { targetConnections=3; }
    else if ( r > 0.8 ) { targetConnections=2; }
    else { targetConnections=1; }

    while ( numConnections < targetConnections )
    {
    _ConnectOne( x, y, _random( 3.5 ) );
    numConnections = _ConnectionCount(x, y);
    }

    }
    }
    }());

    #792

    Andy Buchanan

    Okay, I give up. This is mangling the code.

    #793

    audiocommander
    Keymaster

    Hi Andy,

    1. you can halt Procoding on OSX with cmd+. (dot). It may take a while, but usually this should stop the execution in case the app isn’t reacting to user input anymore (for example, if your code is stuck inside a loop).

    2. If you need to recover parts of the sketch, you can go to the location of your sketch in the Finder, select the file, right-click and select “show package contents”. For HTML5 Canvas projects, you’ll find your sketch code in the canvas.js file.

    3. There are a couple of things that are wrong with your code; as I don’t know what you are trying to do, I can’t say much, but you have
    – a wrong number of brackets
    – a wrong statement (x 0.98) makes no sense
    – an “else if” but no “if”
    – a “while” loop inside a “for” loop which is a quite dangerous thing to do, esp. in JavaScript which is running mostly on the main thread. So (as you found out) this might block the user interface.
    – your second for loop (targetConnections=4) looks like it should be an if statement? Really can’t say…

    Usually, the JSHint code checker should find your errors and point at least to “x 0.98” as well as the “else if”. If the code does not evaluate, it won’t be loaded in the editor, so at this point, I really don’t know why the program should hang. I guess it should rather show you a black preview with some error output.

    To make sure your code works as expected, see when “numConnections” is lower than “targetConnections” and “y” is lower than “_h”. I guess at some point that just isn’t the case.

    Best,
    Michael

    #794

    audiocommander
    Keymaster

    ps: this line looks like a copy & paste error (or like you accidentally deleted one line)

    for ( var x=0; x 0.98 ) { targetConnections=4; }

    it looks like it should be something like:

    for (var x=0; x<_h ; x++) {
         if(r > 0.98) { targetConnections = 4; }
         else if(r > 0.9) { targetConnections = 3; } …

    #796

    Andy Buchanan

    Hi, thanks for the reply. With regards to point 3, the code is actually not that broken!. This forum edit box won’t post the code correctly for some reason ( I’m on the latest Chrome ), it chucks half of it away, hence the word salad you got to see :-/. I will check that the while loop cannot stick, it shouldn’t but I will check. Certainly, the problems was with the editor or jslint, not the execution…

    #797

    Andy Buchanan

    Okay, it is the code “sticking” under rare circumstances. I have not succeeded in Cmd-. breaking on any occasion, I’ve waited for up to 5 minutes. I’ve had to force quit the program, then extract the js code and open it as a new file – otherwise it’ll just hang again. Am I missing a way to temporarily disable the canvas? I am new to your program. ( Liking it quite a lot so far, aside from this annoyance ).

    Cheers,
    Andy

    #798

    audiocommander
    Keymaster

    Hi Andy,

    in case the sketch hangs, you need to constantly press cmd+.

    Your sketch hangs, because that loop is processed endlessly and thus the user interface is updated very infrequently. Unfortunately, this may happen in other IDEs as well. And if you preview the code in your Browser, it’ll hang or most likely crash the browser as well (Procoding is using Safari’s WebKit WebView). Currently, there is no option to disable the Canvas, because having the preview right next to the code is an integral feature of Procoding.

    However, I have some ideas how I could add a “hang”-detector and provide a panel with a way to stop the execution. I will consider adding something like this.

    What you can do right now in order to fix your code is:
    – Remove the loop, so you can check if the inside of the loop does what you think it should do. If it works as expected, you can wrap it in a loop again.
    – Restrict your loop condition; so instead of checking y against _h, check if y is lower than (for example) 5 and make sure you increment y. In other words: make absolutely sure your loop will exit.
    – Add “debugger;” at the top of your loop and show the console. Step through each line to find why the loop won’t reach an exit point
    – Use console.log() instead of calling other functions to see what’s going wrong
    – instead of using loops (for, while), make use of JavaScripts callback handlers. JS is really nice in taking a function as an argument.

    Hope this helps,
    Michael

    #799

    Andy Buchanan

    Hi, Thanks for the pointers.

    I managed to find and fix the bugs okay. This was an unusual bit of code since it’s recursive and brute force. Not the sort of thing I normally find myself writing, especially in such an unfamiliar language.

    I guess the main issue is that once I had code that had an infinite loop the only way to fix it was to crack open the file package and manually edit the code. Loading the sketch n Procoding would just hang it again before any edits could be made.

    I agree that the live preview is an integral part of the experience, but if I might offer a suggestion.

    1. Perhaps have a nice big obvious icon on the toolbar that can toggle the live updates on/off.
    2. On startup if a reopened file has been opened previously but not marked as “safe” you could set the preview to off.
    ( That way numpties like myself could fix the infinite looping code before continuing :) )

    Thanks for your help. I am enjoying this, and have been making good use of the iOS App too.
    ( Though I am finding the iCloud sync-ing a bit random ).

    Cheers, Andy

    Mazie, my first Procoding Sketch

    #800

    audiocommander
    Keymaster

    Hi Andy,

    wow, that’s a super cool sketch, it’s awesome!
    It looks like you enjoyed JavaScript (and share my enthusiasm about this totally underestimated language for creative coding).

    And thanks for your feedback, I will definitely add some sort of mechanism to handle this kind of situation for the next version.

    I’m aware that iCloud synching does take a while, it syncs fine if you always wait a bit. I am currently thinking about removing the previews from the files to make them smaller and thus faster to sync. But that’s taking away a nice feature as well (as the previews would stay local only this way). I also hope that syncing will improve on Apple’s side, considering that the whole technology is only 2+ years old…

    Best,
    Michael

    btw: if you ever come across this issue again, here’s another (pro) tip:
    if you happen to have Xcode installed, you might also directly edit the info.plist file inside the sketch folder. There’s a “sketch” field, that is actually the location where Procoding stores the sketch text. So if you update this field, it’s like you change it with another program or on another device.

    #803

    Andy Buchanan

    Thanks for the plist tip. I do usually have xcode installed, so that’ll help if I’m boneheaded enough to write more infinite loops!

    I’ve been doing my “syncing” manually with the email for noe since my connection is not always great and the iCloud syncing doesn’t really give much feedback.

    #805

    Andy Buchanan

    I’m loving the immediacy of this medium. Can’t wait for WebGL to appear! :-)

    #810

    audiocommander
    Keymaster

    Hi Andy,

    fyi –
    while I’m working on a Hang-Detection to prevent crashes of the IDE all together, I added a quick emergency preference option to not load and display the sketch at all.

    This way, in case Procoding crashes or hangs, you can:
    – force-quit Procoding with cmd+alt+esc
    – Press the SHIFT key while opening Procoding again (or deactivate the windows restoring feature of mountain lion in system preferences > general setting)
    – In Procoding, go to Preferences and tick “Emergency Canvas Lock” (aka there’s a similar setting in the iOS version)
    – open the sketch & fix it
    – Deactivate the “Emergency Canvas Lock” preference again
    – Re-open the document

    It’s not perfect, but a quick solution for a small problem that has been bugging me as well from time to time.

    This feature is included in the upcoming maintenance update (Procoding 2.2), which is waiting for review and will probably be reviewed and released within the next two weeks.

    Thanks again for contacting me,
    Michael

    #811

    Andy Buchanan

    Hi Michael,

    Thanks for this, that’ll make things a little easier!

    I do seem to write an awful lot of infinite loops – party just normal bugginess, but also often down to coding style – i.e. I write the loop, then fill in the details/terminating conditions etc, which is sometimes leaving me with a hang if the canvas updates before I’m done.

    I guess I’ll try to write loops that just fall through rather than inf. loop before I finish constructing them – while(false) :-)

    Cheers,
    Andy

Viewing 15 posts - 1 through 15 (of 15 total)

The topic ‘OSX. Sketch that hangs’ is closed to new replies.