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

Attempted to push invalid value of type DynamicStruct, expected Handle<T> #2215

Closed
lassade opened this issue May 18, 2021 · 2 comments
Closed
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior

Comments

@lassade
Copy link
Contributor

lassade commented May 18, 2021

Bevy version

main branch cb98d31

Operating system & version

Fedora 33

What you did

I'm trying to spawn a component with vec of Handle<Clip> with at least one instance, but Handle::<T>::clone_value() returns a boxed DynamicStruct instead of a clone of the Handle<T>, which leads to an error rising from the list_apply function that can't handle a DynamicStruct;

That also affects simple things like this:

use bevy::prelude::*;

#[derive(Default, Debug, Clone, Reflect)]
struct Something {
    val: usize,
}

#[derive(Default, Debug, Reflect)]
#[reflect(Component)]
struct ComponentA {
    list: Vec<Something>,
}

fn setup(mut commands: Commands, mut scenes: ResMut<Assets<Scene>>) {
    let mut world = World::new();
    world.spawn().insert(ComponentA {
        list: vec![Something { val: 0 }],
    });

    let scene_handle = scenes.add(Scene::new(world));
    commands.spawn_scene(scene_handle);
}

fn main() {
    App::build()
        .register_type::<ComponentA>()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup.system())
        .run();
}

even though Something implements Clone the Reflect::clone_value returns a DynamicStruct instead;

What you expected to happen

The scene should spawn no problem

What actually happened

Panics

thread 'main' panicked at 'Attempted to push invalid value of type bevy_animation_tests::Something.', /home/lassade/Rust/bevy/crates/bevy_reflect/src/impls/std.rs:59:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Segmentation fault (core dumped)

Additional information

My ideas to solve this issue are:

  1. Add support for DynamicStructs in list_apply ()
  2. Change the Reflect implementation for Handle<T>
  3. Maybe change the Reflect behavior to require a Clone impl by default and add an option to use dynamic bundle instead

I think 1 and 2 must be done, 3 doesn't solve the problem but I think it at least will make it more clearer and maybe faster;

@lassade lassade added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 18, 2021
@alice-i-cecile alice-i-cecile added A-Reflection Runtime information about types and removed S-Needs-Triage This issue needs to be labelled labels May 18, 2021
@mockersf
Copy link
Member

mockersf commented Feb 2, 2022

is this fixed by #1395 ?

@MrGVSV
Copy link
Member

MrGVSV commented Oct 18, 2022

Closing as this particular issue (getting the concrete type from a Dynamic one) is solved using FromReflect.

@MrGVSV MrGVSV closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior
Projects
Status: Done
Development

No branches or pull requests

4 participants