From 01aaa904c8a3fea7b558155d99ac17a9c4a83064 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 7 Oct 2013 23:34:16 -0400 Subject: Add error handling in game loop. Print backtrace and pause game when exceptions occur. This way the developer can fix the error and resume the game rather than the game crashing, forcing the developer to restart the game. The REPL remains active when the game is paused, of course. --- 2d/game-loop.scm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/2d/game-loop.scm b/2d/game-loop.scm index a0ce798..e8e1099 100644 --- a/2d/game-loop.scm +++ b/2d/game-loop.scm @@ -240,11 +240,19 @@ the stack." (run-repl) (SDL:delay tick-interval) accumulator) - (let ((remainder (update accumulator))) - (run-repl) - (render dt) - (switch-scenes-maybe) - remainder))) + (catch #t + (lambda () + (let ((remainder (update accumulator))) + (run-repl) + (render dt) + (switch-scenes-maybe) + remainder)) + (lambda (key . args) + (pause-game) + accumulator) + (lambda (key . args) + (display-backtrace (make-stack #t) + (current-output-port)))))) (define (game-loop last-time accumulator) "Update game state, and render. LAST-TIME is the time in -- cgit v1.2.3