Closed ghost closed 10 years ago
I have been thinking about ways to help you recover from errors better. One thing that is already available in the current version of play-clj.core is a function called wrapper
, which wraps around all screen functions. The purpose of it is to let you redefine it so you can control how these functions are run.
For example, try doing something like the following, which redefines wrapper
to catch any errors and switch to a blank screen. Once the error is corrected, you can switch back to the main screen. Note that you can just do (on-gl (set-screen! mental-math fight-screen))
if you're on the latest version.
(defscreen blank-screen
:on-render
(fn [screen entities]
(clear!)))
(intern 'play-clj.core
'wrapper
(fn [screen f]
(try (f)
(catch Exception e (.printStackTrace e)
(on-gl (set-screen! my-game blank-screen))))))
Thanks, that works perfectly! A debug screen that displays the stack trace and resets to the original screen on
oh except I had to change on-gl to 'on-gl
Great, I'm glad it helped. I've been thinking about adding it to the library as a standard feature. I could enable it by default, or perhaps provide a something like (catch-screen-errors! true)
.
You probably don't need on-gl
at all in the catch statement, now that I think about it, because it should already be on the GL thread.
I decided I don't want to hard-code this behavior into the library, but I also don't want it to remain a hidden feature. So, I'm adding this: (set-screen-wrapper! wrapper-fn)
. It doesn't really save you from writing much code, because it does the equivalent of (intern 'play-clj.core 'wrapper wrapper-fn)
. However, it will be an explicit part of the documentation, so more people will be aware of it.
Using a LightTable repl connection: Basically anything breaks the code will throw an exception after running
Then after re-evaling the fixed code and :post-runnable the window stays broken. Currently I'm just disconnecting/reconnecting