summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee.scm22
1 files changed, 15 insertions, 7 deletions
diff --git a/chickadee.scm b/chickadee.scm
index 52cbcce..74faa56 100644
--- a/chickadee.scm
+++ b/chickadee.scm
@@ -28,9 +28,12 @@
(define (call-with-error-handling handler thunk)
(let ((stack #f))
(catch #t
- thunk
+ (lambda ()
+ (thunk)
+ #f)
(lambda (key . args)
- (error stack key args))
+ (handler stack key args)
+ #t)
(lambda (key . args)
(set! stack (make-stack #t 3))))))
@@ -72,15 +75,20 @@
(delta (- current-time previous-time)))
(let update-loop ((buffer (+ buffer delta)))
(if (>= buffer timestep)
- (begin
- (with-error-handling error (update timestep))
- (update-loop (- buffer timestep)))
+ ;; Short-circuit the update loop if an error
+ ;; occurred, and reset the current time to now in
+ ;; order to discard the undefined amount of time
+ ;; that was spent handling the error.
+ (if (with-error-handling error (update timestep))
+ (loop (time) 0)
+ (update-loop (- buffer timestep)))
(begin
;; We render upon every iteration of the loop, and
;; thus rendering is decoupled from updating.
;; It's possible to render multiple times before
;; an update is performed.
- (with-error-handling error (render (/ buffer timestep)))
- (loop current-time buffer)))))))
+ (if (with-error-handling error (render (/ buffer timestep)))
+ (loop (time) 0)
+ (loop current-time buffer))))))))
(lambda (cont callback)
#f))))