-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Dropping NonSend resources is unsound #3310
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorP-HighThis is particularly urgent, and deserves immediate attentionThis is particularly urgent, and deserves immediate attentionP-UnsoundA bug that results in undefined compiler behaviorA bug that results in undefined compiler behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
Description
Bevy version
0.5 (and present main)
What you did
use bevy::prelude::*;
use std::cell::UnsafeCell;
struct MyNonSend(UnsafeCell<()>);
impl Drop for MyNonSend {
fn drop(&mut self) {
dbg!("dropped");
}
}
fn main() {
let mut world = World::new();
world.insert_non_send(MyNonSend(UnsafeCell::new(())));
std::thread::spawn(move || {
drop(world);
})
.join()
.unwrap();
}What you expected to happen
The NonSend resource is dropped correctly.
What actually happened
"Dropped" is printed.
Additional information
Full credit to @TheRawMeatball, @jakobhellermann @BoxyUwU and @DJMcNab. Blame them; I'm just the ticketmaster!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorP-HighThis is particularly urgent, and deserves immediate attentionThis is particularly urgent, and deserves immediate attentionP-UnsoundA bug that results in undefined compiler behaviorA bug that results in undefined compiler behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished