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

Removing any elements from KayakApp causes a panic #166

Open
bayou-brogrammer opened this issue Nov 14, 2022 · 3 comments
Open

Removing any elements from KayakApp causes a panic #166

bayou-brogrammer opened this issue Nov 14, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@bayou-brogrammer
Copy link
Contributor

Using the hello_world as an example, if I have the following setup:

fn startup(
    mut commands: Commands,
    mut font_mapping: ResMut<FontMapping>,
    asset_server: Res<AssetServer>,
) {
    font_mapping.set_default(asset_server.load("roboto.kayak_font"));

    let mut widget_context = KayakRootContext::new();
    widget_context.add_plugin(KayakWidgetsContextPlugin);
    let parent_id = None;
    rsx! {
        <KayakAppBundle>
            <TextWidgetBundle
                text={TextProps {
                    content: "Hello World".into(),
                    size: 20.0,
                    ..Default::default()
                }}
            />
        </KayakAppBundle>
    }

    commands.spawn(UICameraBundle::new(widget_context));
}
fn remove_child(
    mut commands: Commands,
    keys: Res<Input<KeyCode>>,
    q: Query<Entity, With<TextProps>>,
) {
    if keys.just_pressed(KeyCode::Space) {
        q.iter().for_each(|e| {
            commands.entity(e).despawn_recursive();
        });
    }
}

And if I say remove the TextWidgetBundle from the KayakApp, it causes a panic. This goes for anything under the RootContext, if i try to remove KayakApp it panics as well

@bayou-brogrammer bayou-brogrammer changed the title Remove any elements from KayakApp causes a panic Removing any elements from KayakApp causes a panic Nov 14, 2022
@StarArawn
Copy link
Owner

What is happening is that the entities are despawned but they still exist in the tree(which lives in context). I think we need a way of resetting the context. Still a question arises from this, what should happen when a widget entity is despawned? Should it be auto removed from the tree? Should we ignore and error or warn in the console?

@StarArawn StarArawn added the bug Something isn't working label Nov 14, 2022
@bayou-brogrammer
Copy link
Contributor Author

bayou-brogrammer commented Nov 14, 2022

NMy first pass thought would be to treat it as a react virtual DOM would where removing an element from the dom, alienates it from the context and allows it to be flushed.

I think there should be a warning of an element inside of the tree is attempted to access, but doesn't exist. But this would require a method or methods ontop of the context that allows for removing entities.

Definitely a tricky situation since the easiest solution in bevy is to remove entities recursively like I have shown, but that won't pull them from the context.

EDIT: a first pass I would say remove entities from the tree if they no longer exist within bevy. A second pass might allow for a better use case where we can flush a context and rebuild it forcing any entities not alive to be removed

@StarArawn
Copy link
Owner

@lecoqjacob Is this still an issue? I'm pretty sure I made some changes which should help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants