-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VertexStream::new_with_stride() pointer parameter leads to easy segfault #52
Comments
What would you suggest as a proper API? |
Probably take an &[T] instead of a raw pointer. |
but since T are stored with strides: eg a slice of [T, U, T, U, T, U] My idea would be to simply take *const u8 and acknowledge the unsafeness. I'm not sure how stride can be encoded safely and VertexStream isn't used in many functions |
Oh, you're right :/. Would &[u8] be an issue? Or *const u8 would probably be fine, but I want something that makes passing |
&[u8] could be a good idea! I guess users would use bytemuck which would solve a few problems with getting this right along with a nice lifetime Also starts to look a lot like a static VertexDataAdapter |
Opened #60 if you want to take a look |
@JMS55 how are you using the stream? Now that I'm reading the API more carefully I'm not sure if it's possible to have an offset inside a vertex struct using a slice. I'm also not sure how meshopt knows where the stream ends and I don't understand the "stream" name since it's finite really. |
I use it to get a position-only stream of the vertices https://github.com/bevyengine/bevy/blob/main/crates/bevy_pbr/src/meshlet/from_mesh.rs#L98-L101.
|
This only works because position is the first element :/ I'm not sure how it'd look if you only wanted scale or rotation for example |
What I tried doing (and got a segfault with):
What you actually need to do:
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>().
The text was updated successfully, but these errors were encountered: