mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
Fix size of MeshVertexAttributeId to be platform independent (#6624)
# Objective `MeshVertexAttributeId` is currently a wrapper type around a `usize`. Application developers are exposed to the `usize` whenever they need to define a new custom vertex attribute, which requires them to generate a random `usize` ID to avoid clashes with any other custom vertex attributes in the same application. As the range of a `usize` is platform dependent, developers on 64-bit machines may inadvertently generate random values which will fail to compile for a 32-bit target. The use of a `usize` here encourages non-portable behaviour and should be replaced with a fixed width type. ## Solution In this PR I have changed the ID type from `usize` to `u64`, but equally a `u32` could be used at the risk of breaking some extant non-portable programs and increasing the chance of an ID collision.
This commit is contained in:
parent
bd8faa7ae1
commit
defeeb375b
1 changed files with 3 additions and 3 deletions
|
@ -1289,7 +1289,7 @@ pub struct MeshVertexAttribute {
|
|||
|
||||
/// The _unique_ id of the vertex attribute. This will also determine sort ordering
|
||||
/// when generating vertex buffers. Built-in / standard attributes will use "close to zero"
|
||||
/// indices. When in doubt, use a random / very large usize to avoid conflicts.
|
||||
/// indices. When in doubt, use a random / very large u64 to avoid conflicts.
|
||||
pub id: MeshVertexAttributeId,
|
||||
|
||||
/// The format of the vertex attribute.
|
||||
|
@ -1297,7 +1297,7 @@ pub struct MeshVertexAttribute {
|
|||
}
|
||||
|
||||
impl MeshVertexAttribute {
|
||||
pub const fn new(name: &'static str, id: usize, format: VertexFormat) -> Self {
|
||||
pub const fn new(name: &'static str, id: u64, format: VertexFormat) -> Self {
|
||||
Self {
|
||||
name,
|
||||
id: MeshVertexAttributeId(id),
|
||||
|
@ -1311,7 +1311,7 @@ impl MeshVertexAttribute {
|
|||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
|
||||
pub struct MeshVertexAttributeId(usize);
|
||||
pub struct MeshVertexAttributeId(u64);
|
||||
|
||||
impl From<MeshVertexAttribute> for MeshVertexAttributeId {
|
||||
fn from(attribute: MeshVertexAttribute) -> Self {
|
||||
|
|
Loading…
Reference in a new issue