Skip to content

Commit

Permalink
render: Use correct length when creating Material resources from Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
caseif committed Dec 6, 2024
1 parent 903ae28 commit 92ab515
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ 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,
}

impl FfiWrapper for Material {
fn of(handle: argus_material_t) -> Self {
Self {
handle,
len: unsafe { argus_material_len() },
must_delete: false,
}
}
Expand All @@ -49,6 +51,7 @@ impl Material {
);
Self {
handle,
len: argus_material_len(),
must_delete: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions engine/static/render/src/cabi/common/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> shader_uids_vec;
shader_uids_vec.reserve(shader_uids_count);
Expand Down

0 comments on commit 92ab515

Please sign in to comment.