From a00552ea79d953578b71d5e3030128d3b22ad9f4 Mon Sep 17 00:00:00 2001 From: "Tommy D. Rossi" Date: Sun, 30 Mar 2025 18:00:07 +0200 Subject: [PATCH] Fix exportImageToMemory (#232) * fix exportImageToMemory * update make_return_cast --- lib/generate_functions.py | 2 ++ lib/raylib.zig | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/generate_functions.py b/lib/generate_functions.py index 4e38f16..2fb26e4 100755 --- a/lib/generate_functions.py +++ b/lib/generate_functions.py @@ -122,6 +122,8 @@ def add_namespace_to_type(t: str) -> str: def make_return_cast(source_type: str, dest_type: str, inner: str) -> str: if source_type == dest_type: return inner + if "ExportImageToMemory" in inner: + return f"{inner}[0..@as(usize, @intCast(fileSize.*))]" if source_type in ["[*c]const u8", "[*c]u8"]: return f"std.mem.span({inner})" diff --git a/lib/raylib.zig b/lib/raylib.zig index f03dc08..1603144 100644 --- a/lib/raylib.zig +++ b/lib/raylib.zig @@ -3838,7 +3838,7 @@ pub fn exportImage(image: Image, fileName: [:0]const u8) bool { /// Export image to memory buffer pub fn exportImageToMemory(image: Image, fileType: [:0]const u8, fileSize: *i32) [:0]u8 { - return std.mem.span(cdef.ExportImageToMemory(image, @as([*c]const u8, @ptrCast(fileType)), @as([*c]c_int, @ptrCast(fileSize)))); + return cdef.ExportImageToMemory(image, @as([*c]const u8, @ptrCast(fileType)), @as([*c]c_int, @ptrCast(fileSize)))[0..@as(usize, @intCast(fileSize.*))]; } /// Export image as code file defining an array of bytes, returns true on success