summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-08-25 22:07:07 -0400
committerDavid Thompson <dthompson2@worcester.edu>2018-08-25 22:07:07 -0400
commit7d64cb370bd5abcdaed9215a33bc450c0bb21bf4 (patch)
tree83d3354b055cfa6fceef10b644a73f6fe11e4334
parent50a9c810166781c12ab970d042642606dfb0d328 (diff)
Fix error handling logic.
* chickadee.scm (call-with-error-handling): Call the correct error handler. Return #t if an error occurred, #f otherwise. (run-game): Reset current-time and buffer after recovering from an error.
-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))))