From 92ab515e8f32971c74fbce90ab79f39cf66b2b16 Mon Sep 17 00:00:00 2001 From: Max Roncace Date: Fri, 6 Dec 2024 02:00:22 -0500 Subject: [PATCH] render: Use correct length when creating Material resources from Rust --- .../render_rustabi/src/argus/render/common/material.rs | 5 ++++- engine/auxiliary/render_rustabi/src/render_cabi/bindings.rs | 1 + .../render/include/argus/render/cabi/common/material.h | 2 ++ engine/static/render/src/cabi/common/material.cpp | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/auxiliary/render_rustabi/src/argus/render/common/material.rs b/engine/auxiliary/render_rustabi/src/argus/render/common/material.rs index 600994ba..fb21b6ed 100644 --- a/engine/auxiliary/render_rustabi/src/argus/render/common/material.rs +++ b/engine/auxiliary/render_rustabi/src/argus/render/common/material.rs @@ -22,7 +22,8 @@ use lowlevel_rustabi::argus::lowlevel::FfiWrapper; use crate::render_cabi::*; pub struct Material { - handle: argus_material_t, + pub handle: argus_material_t, + pub len: usize, must_delete: bool, } @@ -30,6 +31,7 @@ impl FfiWrapper for Material { fn of(handle: argus_material_t) -> Self { Self { handle, + len: unsafe { argus_material_len() }, must_delete: false, } } @@ -49,6 +51,7 @@ impl Material { ); Self { handle, + len: argus_material_len(), must_delete: true, } } diff --git a/engine/auxiliary/render_rustabi/src/render_cabi/bindings.rs b/engine/auxiliary/render_rustabi/src/render_cabi/bindings.rs index 1cf36257..1a6b486c 100644 --- a/engine/auxiliary/render_rustabi/src/render_cabi/bindings.rs +++ b/engine/auxiliary/render_rustabi/src/render_cabi/bindings.rs @@ -642,6 +642,7 @@ extern "C" { canvas: argus_canvas_t, id: *const ::std::os::raw::c_char, ); + pub fn argus_material_len() -> usize; pub fn argus_material_new( texture_uid: *const ::std::os::raw::c_char, shader_uids_count: usize, diff --git a/engine/static/render/include/argus/render/cabi/common/material.h b/engine/static/render/include/argus/render/cabi/common/material.h index 5fb466a7..d4d21646 100644 --- a/engine/static/render/include/argus/render/cabi/common/material.h +++ b/engine/static/render/include/argus/render/cabi/common/material.h @@ -26,6 +26,8 @@ extern "C" { typedef void *argus_material_t; +size_t argus_material_len(void); + argus_material_t argus_material_new(const char *texture_uid, size_t shader_uids_count, const char *const *shader_uids); void argus_material_delete(argus_material_t material); diff --git a/engine/static/render/src/cabi/common/material.cpp b/engine/static/render/src/cabi/common/material.cpp index 054accdc..85ccfa1f 100644 --- a/engine/static/render/src/cabi/common/material.cpp +++ b/engine/static/render/src/cabi/common/material.cpp @@ -34,6 +34,10 @@ static inline const argus::Material &_as_ref(argus_material_t material) { extern "C" { +size_t argus_material_len(void) { + return sizeof(argus::Material); +} + argus_material_t argus_material_new(const char *texture_uid, size_t shader_uids_count, const char *const *shader_uids) { std::vector shader_uids_vec; shader_uids_vec.reserve(shader_uids_count);