summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2013-10-07 23:34:16 -0400
committerDavid Thompson <dthompson2@worcester.edu>2013-10-23 19:44:51 -0400
commit01aaa904c8a3fea7b558155d99ac17a9c4a83064 (patch)
tree36696176c04a56071a36339ac97e6768790c7b49 /2d
parent0f0add2164f6b01f79d7ba486316262de614a89d (diff)
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.
Diffstat (limited to '2d')
-rw-r--r--2d/game-loop.scm18
1 files 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