Skip to content

Drop called multiple times if drop panics. #2597

Closed
@mahkoh

Description

@mahkoh

Bevy version

Master

Operating system & version

Arch Linux

What you did

use bevy::prelude::*;

struct Dropper(i32);

impl Drop for Dropper {
    fn drop(&mut self) {
        println!("drop {}", self.0);
        if self.0 == 0 {
            panic!();
        }
    }
}

fn main() {
    App::new()
        .add_startup_system(setup.system())
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn()
        .insert(Dropper(0))
        .insert(Dropper(1));
}

What you expected to happen

drop 0 is printed at most once.

What actually happened

drop 0 is printed twice.

Additional information

Several functions in https://github.com/bevyengine/bevy/blob/43d99bb583866c1adb4aa88f19b88637df0a7f33/crates/bevy_ecs/src/storage/blob_vec.rs do not handle self.drop unwinding (nor require their callers to do so.)

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions