Sketch Lifecycles

73 views
Skip to first unread message

nick rothwell

unread,
Aug 4, 2014, 3:51:16 PM8/4/14
to clj-pro...@googlegroups.com
A couple of lifecycle things:

(i) I'm running with :features [:no-safe-fns] for development - if something bombs out, it's nice to have a single copy of a stack trace, rather than 60 of them per second. But if something does go wrong, then the sketch hangs and can't be closed with the window button. Is there a way of closing the sketch?

(ii) Perhaps related: I've got everything configured using the Stuart Sierra workflow setup (http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded), which works fine, except that there's no apparent way to shut down the current sketch in code, so it's not possible to automate the teardown/restart process. Or am I missing some bit of API here?

Nikita Beloglazov

unread,
Aug 4, 2014, 4:56:10 PM8/4/14
to clj-pro...@googlegroups.com
Hi Nick

Have you tried pause-on-error middleware? It was introduced in Quil 2.2.0. Here is docstring: https://github.com/quil/quil/blob/master/src/cljx/quil/middleware.cljx#L17

It should solve the problem you have: on error, sketch pauses and doesn't bombard you with tons of exceptions every second. Instead it waits until press any button and only then continues.

Thanks,
Nikita


--
You received this message because you are subscribed to the Google Groups "clj-processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-processin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikita Beloglazov

unread,
Aug 5, 2014, 5:00:36 PM8/5/14
to clj-pro...@googlegroups.com
Following up. If you want to manually close sketch after exception you can try calling .dispose on sketch object. It should close sketch. Something like this:

(defsketch my-sketch
  :draw ...
  :setup ..)

(.dispose my-sketch)


or

(def my-sketch (sketch :draw ... :setup ...))

(.dispose my-sketch)


Nikita
To unsubscribe from this group and stop receiving emails from it, send an email to clj-processing+unsubscribe@googlegroups.com.

Nikita Beloglazov

unread,
Aug 5, 2014, 5:02:27 PM8/5/14
to clj-pro...@googlegroups.com
Sorry, it was wrong.

Correct way is (.. my-sketch frame dispose)

nick rothwell

unread,
Aug 7, 2014, 10:03:07 AM8/7/14
to clj-pro...@googlegroups.com
A quick test suggests that pause-on-error doesn't work out of the box with fun-mode : I get the error text in the sketch, but then it won't recover. Perhaps something odd comes back from update() - I'll investigate.

Nikita Beloglazov

unread,
Aug 7, 2014, 10:10:35 AM8/7/14
to clj-pro...@googlegroups.com
Did you specify pause-on-error middleware before fun-mode in :middleware vector? It should go first, otherwise it might not work.

nick rothwell

unread,
Aug 7, 2014, 10:26:04 AM8/7/14
to clj-pro...@googlegroups.com
Perfect - thanks!

(Aside: I've never ever used ".." - "(-> my-sketch (.frame) (.dispose))" is more to my taste...)

nick rothwell

unread,
Aug 8, 2014, 6:59:06 AM8/8/14
to clj-pro...@googlegroups.com
Nope, I had them the other way round. Thanks: seems to work now!
Reply all
Reply to author
Forward
0 new messages