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
					
				| @ -1289,7 +1289,7 @@ pub struct MeshVertexAttribute { | |||||||
| 
 | 
 | ||||||
|     /// The _unique_ id of the vertex attribute. This will also determine sort ordering
 |     /// 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"
 |     /// 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, |     pub id: MeshVertexAttributeId, | ||||||
| 
 | 
 | ||||||
|     /// The format of the vertex attribute.
 |     /// The format of the vertex attribute.
 | ||||||
| @ -1297,7 +1297,7 @@ pub struct MeshVertexAttribute { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl 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 { |         Self { | ||||||
|             name, |             name, | ||||||
|             id: MeshVertexAttributeId(id), |             id: MeshVertexAttributeId(id), | ||||||
| @ -1311,7 +1311,7 @@ impl MeshVertexAttribute { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)] | #[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)] | ||||||
| pub struct MeshVertexAttributeId(usize); | pub struct MeshVertexAttributeId(u64); | ||||||
| 
 | 
 | ||||||
| impl From<MeshVertexAttribute> for MeshVertexAttributeId { | impl From<MeshVertexAttribute> for MeshVertexAttributeId { | ||||||
|     fn from(attribute: MeshVertexAttribute) -> Self { |     fn from(attribute: MeshVertexAttribute) -> Self { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Robin KAY
						Robin KAY