From 5b6fd432dedc39f2ba0ed3e01ab39d1673698fc2 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sun, 16 Aug 2026 19:38:26 +0700 Subject: [PATCH] Improve engine error handling, add unload call, reset atoms --- src/engine.clj | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/engine.clj b/src/engine.clj index a813703..2345a68 100644 --- a/src/engine.clj +++ b/src/engine.clj @@ -18,14 +18,19 @@ (println e)))) (defn run-game! - [{:keys [title width height config-path init input update draw watch-fn] + [{:keys [title width height config-path init input update draw unload watch-fn] :or {title "Untitled" width 1200 height 900 watch-fn (constantly nil)}}] (rl/set-trace-log-level! rl/log-warning) (rl/init-window! width height title) (rl/set-target-fps! 60) - (let [config (edn/read-string (slurp config-path))] + (let [config (if config-path + (edn/read-string (slurp config-path)) + {})] (reset! game-config {:config-path config-path :config config}) - (reset! game-state (init config)) + (try + (reset! game-state (init config)) + (catch Throwable t + (println t))) (while (not (rl/window-should-close?)) (if @last-error (Thread/sleep 50) @@ -40,4 +45,12 @@ (println t) (reset! last-error t) (w/watch! (merge (watch-fn config @game-state) {:error t})))))))) - (rl/close-window!))) + (try + (when unload + (unload @game-state)) + (catch Throwable t + (println t))) + (rl/close-window!) + (reset! last-error nil) + (reset! game-state nil) + (reset! game-config nil)))