From 7fffdd4798fafcf6ead10b777bbe0b48ae8e229a Mon Sep 17 00:00:00 2001 From: tali Date: Sat, 20 Jan 2024 12:23:35 -0500 Subject: [PATCH] fix "not found" errors for textures by handling in absolute_path --- src/s2/asset.ml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/s2/asset.ml b/src/s2/asset.ml index 0c1e901..4519d76 100644 --- a/src/s2/asset.ml +++ b/src/s2/asset.ml @@ -4,15 +4,13 @@ include (val Ohlog.sublogs logger "Asset") exception Error of string * string let absolute_path path = - Unix.realpath (Printf.sprintf "assets/%s" path) + try Unix.realpath (Printf.sprintf "assets/%s" path) + with Unix.Unix_error (ENOENT, _, _) -> + raise (Error (path, "not found")) let load_file path = trace (fun m -> m "open text file %S" path); - let fd = - try Unix.openfile (absolute_path path) [O_RDONLY] 0 - with Unix.Unix_error (ENOENT, _, _) -> - raise (Error (path, "not found")) - in + let fd = Unix.openfile (absolute_path path) [O_RDONLY] 0 in let len = (Unix.fstat fd).st_size in let buf = Bytes.create len in trace (fun m -> m "length=%d" len);