gwihlidal / meshopt-rs

Rust ffi and idiomatic wrapper for zeux/meshoptimizer, a mesh optimization library that makes indexed meshes more GPU-friendly.
Apache License 2.0
163 stars 33 forks source link

VertexStream::new_with_stride() pointer parameter leads to easy segfault #52

Open JMS55 opened 1 month ago

JMS55 commented 1 month ago

What I tried doing (and got a segfault with):

VertexStream::new_with_stride::<Vec3, _>(
    &vertex_buffer, // vertex_buffer is a Vec<u8>
    vertex_stride,
)

What you actually need to do:

VertexStream::new_with_stride::<Vec3, _>(
    vertex_buffer.as_ptr(),
    vertex_stride,
)

I suggest changing the function to not take a raw pointer.

The whole T vs VertexType thing was also confusing to me, it took me a while to figure out how to use the function. I'd prefer simply passing the size myself rather than it using size_of::\<T>().