Skip to content

World entity access is not sound #3408

@odanek

Description

@odanek

Bevy version

0.5

Operating system & version

Windows 10

What you did

The World entity api allows use after free

use bevy::prelude::*;

struct Name(String);

fn test(world: &mut World) {
    let mut entity = world.spawn();
    entity.insert(Name("Test".to_string()));
    let name = entity.get::<Name>().unwrap();    
    entity.despawn(); // Or entity.remove::<Name>();
    println!("{}", name.0); // This line should be a compile error
}

fn main() {
    App::build()
        .add_system(test.exclusive_system())
        .run();
}

What you expected to happen

The code should not compile

What actually happened

The code compiles without any errors or warnings

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorP-HighThis is particularly urgent, and deserves immediate attention

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions