Rust-GPU/rust-gpu

`cannot cast between pointer types: from *f32x2, to *struct ...` in latest versions of `rust-gpu`

Closed this issue · 2 comments

tombh commented

Expected Behaviour

At some point after September 6th (#4c633aec) the following code stopped compiling.

pub struct Particles {
    pub indices: Indices,
    pub data: [Particle; MAX_PARTICLES_IN_CELL * REQUIRED_CELLS],
    pub centre_count: usize,
}

impl Particles {
    pub fn new(
        ...
    ) -> Self {
        let mut particles = Self {
            data: [Particle::default(); MAX_PARTICLES_IN_CELL * REQUIRED_CELLS], // error here
            ...
        };

Example & Steps To Reproduce

I'm compiling with latest cargo-gpu (Rust-GPU/cargo-gpu@4623ccb) and the full error is:

error: cannot cast between pointer types
       from `*f32x2`
         to `*struct particle::Particle { position: f32x2, velocity: f32x2, index: u32 }`
   --> shaders/physics/src/particles.rs:56:19
    |
56  |             data: [Particle::default(); MAX_PARTICLES_IN_CELL * REQUIRED_CELLS],
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm happy to bisect to find the exact commit that introduces the change, but just wondering if anybody already knows what the problem is?

Thanks for the report! This might be #46 ? If so the linked PR where it was discovered has a workaround that may work.

tombh commented

Ah yes, indeed that's it. Thank you ✨