Skip to content

Commit

Permalink
Fix some rust FFI (#319)
Browse files Browse the repository at this point in the history
* Fix bind_frag_data_location

rust str is not null terminated

Signed-off-by: sagudev <[email protected]>

* Fix get_transform_feedback_varying

size and tftype must be mutable

CString does not allow multiple nul bytes inside (this causes panic).

Signed-off-by: sagudev <[email protected]>

---------

Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev authored Oct 30, 2024
1 parent b054a51 commit dc2cfad
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@ impl HasContext for Context {
name: &str,
) {
let gl = &self.raw;
let name = CString::new(name).unwrap();
gl.BindFragDataLocation(
program.0.get(),
color_number,
Expand Down Expand Up @@ -4080,25 +4081,25 @@ impl HasContext for Context {
) -> Option<ActiveTransformFeedback> {
let gl = &self.raw;

const buf_size: usize = 256;
const bytes: [u8; buf_size] = [0; buf_size];
const max_name_size: usize = 256;
let mut name_bytes = [0; max_name_size];

let size: i32 = 0;
let tftype: u32 = 0;
let c_name = CString::new(bytes.to_vec()).unwrap();
let c_name_buf = c_name.into_raw();
let mut size = 0;
let mut tftype = 0;

gl.GetTransformFeedbackVarying(
program.0.get(),
index,
buf_size as i32,
name_bytes.len() as i32,
std::ptr::null_mut(),
size as *mut i32,
tftype as *mut u32,
c_name_buf,
&mut size,
&mut tftype,
name_bytes.as_mut_ptr(),
);

let name = CString::from_raw(c_name_buf).into_string().unwrap();
let name = CStr::from_ptr(name_bytes.as_mut_ptr())
.to_string_lossy()
.into_owned();

Some(ActiveTransformFeedback { size, tftype, name })
}
Expand Down

0 comments on commit dc2cfad

Please sign in to comment.