Skip to content
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

cannot find type DVec2 in this scope after cargo clean #266

Open
andrewexton373 opened this issue Dec 13, 2024 · 4 comments
Open

cannot find type DVec2 in this scope after cargo clean #266

andrewexton373 opened this issue Dec 13, 2024 · 4 comments

Comments

@andrewexton373
Copy link

andrewexton373 commented Dec 13, 2024

Hello,

After a cargo clean and fresh build of my project I'm now receiving this error that is originating from the bevy_prototype_lyon crate as far as I can tell:

error[E0412]: cannot find type `DVec2` in this scope
   --> /home/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_prototype_lyon-0.13.0/src/shapes.rs:213:21
    |
213 |     pub points: Vec<DVec2>,
    |                     ^^^^^
    |
   ::: /home/andrew/.cargo/registry/src/index.crates.io-6f17d22bba15001f/glam-0.29.2/src/f32/vec2.rs:21:1
    |
21  | pub struct Vec2 {
    | --------------- similarly named struct `Vec2` defined here
    |
help: a struct with a similar name exists
    |
213 |     pub points: Vec<Vec2>,
    |                     ~~~~
help: you might be missing a type parameter
    |
212 | pub struct Polygon<DVec2> {
    |                   +++++++

Is this a known issue, or an possibly incompatibility with crates I'm pulling in?

Here's my dependency list if it can help provide some context:

ordered-float = "4.5.0"
num = "0.4.3"
bevy = { version = "0.15", features = ["bevy_sprite", "wayland"] }
bevy_egui = "0.31.1"
avian2d = { git = "https://github.com/Jondolf/avian.git", branch = "main", default-features = false, features = ["2d", "f64", "parry-f64", "debug-plugin"] }
bevy_prototype_lyon = "0.13.0"
bevy_tweening = "0.12"
strum = "0.26.3"
strum_macros = "0.26.4"
rand = "0.8.5"
rand_distr = "0.4.3"
geo = "0.29.3"
bevy-inspector-egui = "0.28.0"
bevy-trait-query = "0.7"
hexx = "0.19.0"
big-brain = "0.22"

Let me know your thoughts, thanks! I appreciate any and all input!

@Nilirad
Copy link
Owner

Nilirad commented Dec 14, 2024

I did some research, DVec2 is glam's double-precision version of Vec2.

bevy_prototype_lyon just uses Vec2. I suspect there is some clash with the double-precision features of the avian2d crate. I don't understand though how can it transform Vec2 in my crate into a DVec2.

@andrewexton373
Copy link
Author

That sounds like an accurate suspicion. I created a fresh project just with these dependencies and it's triggering the same compile error:

bevy = "0.15.0"
avian2d = { git = "https://github.com/Jondolf/avian.git", branch = "main", default-features = false, features = ["2d", "f64", "parry-f64", "debug-plugin"] }
bevy_prototype_lyon = "0.13.0"

I'm curious how the transformation from Vec2 to DVec2 is occurring too. My first thought would be the "f64", "parry-f64" feature flags for avian2d, however I'm getting the same error even with those flags removed.

@andrewexton373
Copy link
Author

Hmm, I'm getting the same build error just with bevy and bevy_prototype_lyon dependencies.

bevy = "0.15.0"
bevy_prototype_lyon = "0.13.0"

Anyone with deeper rust knowledge know how the Vec2 gets changed to a DVec2 at compile time in this scenario?

#[derive(Debug, Clone, PartialEq)]
pub struct Polygon {
    pub points: Vec<Vec2>,
    pub closed: bool,
}

The compiler is reporting this as the root of the error, but it's a Vec2 in bevy_prototype_lyon's source code:

pub points: Vec<DVec2>

@andrewexton373
Copy link
Author

Searching for DVec2 in the bevy repo returns some DVec2 definition wrapped in a macro:

impl_reflect!(
    #[reflect(Debug, PartialEq, Default, Deserialize, Serialize)]
    #[type_path = "glam"]
    struct DVec2 {
        x: f64,
        y: f64,
    }
);

The documentation for said macro is follows:

/// A replacement for `#[derive(Reflect)]` to be used with foreign types which
/// the definitions of cannot be altered.
///
/// This macro is an alternative to [`impl_reflect_opaque!`] and [`impl_from_reflect_opaque!`]
/// which implement foreign types as Opaque types. Note that there is no `impl_from_reflect`,
/// as this macro will do the job of both. This macro implements them using one of the reflect
/// variant traits (`bevy_reflect::{Struct, TupleStruct, Enum}`, etc.),
/// which have greater functionality. The type being reflected must be in scope, as you cannot
/// qualify it in the macro as e.g. `bevy::prelude::Vec3`.
///
/// It is necessary to add a `#[type_path = "my_crate::foo"]` attribute to all types.
///
/// It may be necessary to add `#[reflect(Default)]` for some types, specifically non-constructible
/// foreign types. Without `Default` reflected for such types, you will usually get an arcane
/// error message and fail to compile. If the type does not implement `Default`, it may not
/// be possible to reflect without extending the macro.
///
///
/// # Example
/// Implementing `Reflect` for `bevy::prelude::Vec3` as a struct type:
/// ```ignore (bevy_reflect is not accessible from this crate)
/// use bevy::prelude::Vec3;
///
/// impl_reflect!(
///     #[reflect(PartialEq, Serialize, Deserialize, Default)]
///     #[type_path = "bevy::prelude"]
///     struct Vec3 {
///         x: f32,
///         y: f32,
///         z: f32
///     }
/// );
/// ```
#[proc_macro]
pub fn impl_reflect(input: TokenStream) -> TokenStream {
    let ast = parse_macro_input!(input as DeriveInput);
    match_reflect_impls(ast, ReflectImplSource::ImplRemoteType)
}

I'm not sure if this is the right rabbit hole to follow, but it possibly seemed relevant. I need to brush up on rust macros to see if this could be the culprit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants