The Case of the Disappearing Canvas

edited March 2014 in How To...

Here's one for Sherlock Holmes.

I started up Processing 2.1 on my Windows 7 laptop and went to a sketch I had run the day before. I'll call him Ahab. I picked a new source image for my PImage and clicked Run. Something strange - no canvas. It was not to be seen anywhere on my screen. And yet the icon for the canvas was right there on my task bar.

Strange indeed. I am vaguely aware that Processing ties the location at which it chooses to place the canvas to the location of the IDE. So for some reason Processing was positioning the canvas somewhere offscreen.

What to do?

As a test I stopped Ahab and opened up another sketch and clicked run. And there was my canvas - smack dab in the middle of my screen.

Going back to my Ahab sketch, I clicked Run again. Nowhere was my canvas to be seen and yet there was the icon indicating that the session was active. And I know for a fact that the sketch was running because I changed focus to the canvas I couldn't see and pressed 's' as I had incorporated a save function into the sketch. And there on my hard drive was a file with the contents of the screen I couldn't see just as I expected it to be.

With a Ctrl-A and a Ctrl-C I copied Ahab's source code to my clipboard and closed the Ahab sketch window.

With a File -> New and a Ctrl-V I pasted Ahab's code into my new IDE session. I crossed my fingers and clicked Run. And what do you think I saw?

There was my canvas smack in the middle of the screen right where I expected it to be.

Reopening the original Ahab, I clicked Run but no screen to be seen. Using File Explorer, I deleted my Ahab directory and saved the copy of the sketch with a different name.

So while I was able to come up with a solution to the case of the disappearing canvas, I have no idea what was going on inside the Processing environment that led to the canvas to disappear in the first place.

PS - I posted this as a How-To since what I did allowed me to successfully recover from the problem I encountered.

Tagged:

Comments

  • edited March 2014

    Maybe the sketch window's location somehow got set to outside your screen's visible area?

    If it happens again, try adding this line to the start of your draw() function:

    frame.setLocation(displayWidth/2-width/2,displayHeight/2-height/2);
    
  • Hi TfGuy44,

    You know I had totally forgotten about frame.whatever. I'd only used it a couple times in the past and had some problems with the couple of sketches that used it when I migrated from 1.5 to 2.1 (no recall what aspect of frame I was using).

    The code you provided works for me with Processing 2.1 running on Windows 7.

    Thank you for this solution.

Sign In or Register to comment.