Skip to content

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

@lassade

Description

@lassade

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions