fix "not found" errors for textures by handling in absolute_path

This commit is contained in:
tali 2024-01-20 12:23:35 -05:00
parent 93ed4c82fa
commit 7fffdd4798
1 changed files with 4 additions and 6 deletions

View File

@ -4,15 +4,13 @@ include (val Ohlog.sublogs logger "Asset")
exception Error of string * string exception Error of string * string
let absolute_path path = 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 = let load_file path =
trace (fun m -> m "open text file %S" path); trace (fun m -> m "open text file %S" path);
let fd = let fd = Unix.openfile (absolute_path path) [O_RDONLY] 0 in
try Unix.openfile (absolute_path path) [O_RDONLY] 0
with Unix.Unix_error (ENOENT, _, _) ->
raise (Error (path, "not found"))
in
let len = (Unix.fstat fd).st_size in let len = (Unix.fstat fd).st_size in
let buf = Bytes.create len in let buf = Bytes.create len in
trace (fun m -> m "length=%d" len); trace (fun m -> m "length=%d" len);