From 7d64cb370bd5abcdaed9215a33bc450c0bb21bf4 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 25 Aug 2018 22:07:07 -0400 Subject: 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. --- chickadee.scm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'chickadee.scm') 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)))) -- cgit v1.2.3