-
-
Notifications
You must be signed in to change notification settings - Fork 4k
[Merged by Bors] - drop overwritten component data on double insert #2227
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
Changes from all commits
95c211c
5298a26
99542f8
ab8dada
ccd5837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ use crate::{ | |
}; | ||
use bevy_ecs_macros::all_tuples; | ||
use std::{ | ||
cell::UnsafeCell, | ||
marker::PhantomData, | ||
ptr::{self, NonNull}, | ||
}; | ||
|
@@ -343,7 +344,7 @@ impl<'w, T: Component> Fetch<'w> for ReadFetch<T> { | |
let column = tables[archetype.table_id()] | ||
.get_column(state.component_id) | ||
.unwrap(); | ||
self.table_components = column.get_ptr().cast::<T>(); | ||
self.table_components = column.get_data_ptr().cast::<T>(); | ||
} | ||
StorageType::SparseSet => self.entities = archetype.entities().as_ptr(), | ||
} | ||
|
@@ -354,7 +355,7 @@ impl<'w, T: Component> Fetch<'w> for ReadFetch<T> { | |
self.table_components = table | ||
.get_column(state.component_id) | ||
.unwrap() | ||
.get_ptr() | ||
.get_data_ptr() | ||
.cast::<T>(); | ||
} | ||
|
||
|
@@ -387,7 +388,7 @@ impl<T: Component> WorldQuery for &mut T { | |
pub struct WriteFetch<T> { | ||
storage_type: StorageType, | ||
table_components: NonNull<T>, | ||
table_ticks: *mut ComponentTicks, | ||
table_ticks: *const UnsafeCell<ComponentTicks>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pointers are allowed to alias, so this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't do that without creating a reference to the wrong element. This pointer is being offset before reading, thus it represents a reference to the whole vec slice. I can't get rid of that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. |
||
entities: *const Entity, | ||
entity_table_rows: *const usize, | ||
sparse_set: *const ComponentSparseSet, | ||
|
@@ -482,7 +483,7 @@ impl<'w, T: Component> Fetch<'w> for WriteFetch<T> { | |
entities: ptr::null::<Entity>(), | ||
entity_table_rows: ptr::null::<usize>(), | ||
sparse_set: ptr::null::<ComponentSparseSet>(), | ||
table_ticks: ptr::null_mut::<ComponentTicks>(), | ||
table_ticks: ptr::null::<UnsafeCell<ComponentTicks>>(), | ||
last_change_tick, | ||
change_tick, | ||
}; | ||
|
@@ -509,8 +510,8 @@ impl<'w, T: Component> Fetch<'w> for WriteFetch<T> { | |
let column = tables[archetype.table_id()] | ||
.get_column(state.component_id) | ||
.unwrap(); | ||
self.table_components = column.get_ptr().cast::<T>(); | ||
self.table_ticks = column.get_ticks_mut_ptr(); | ||
self.table_components = column.get_data_ptr().cast::<T>(); | ||
self.table_ticks = column.get_ticks_ptr(); | ||
} | ||
StorageType::SparseSet => self.entities = archetype.entities().as_ptr(), | ||
} | ||
|
@@ -519,8 +520,8 @@ impl<'w, T: Component> Fetch<'w> for WriteFetch<T> { | |
#[inline] | ||
unsafe fn set_table(&mut self, state: &Self::State, table: &Table) { | ||
let column = table.get_column(state.component_id).unwrap(); | ||
self.table_components = column.get_ptr().cast::<T>(); | ||
self.table_ticks = column.get_ticks_mut_ptr(); | ||
self.table_components = column.get_data_ptr().cast::<T>(); | ||
self.table_ticks = column.get_ticks_ptr(); | ||
} | ||
|
||
#[inline] | ||
|
@@ -531,7 +532,7 @@ impl<'w, T: Component> Fetch<'w> for WriteFetch<T> { | |
Mut { | ||
value: &mut *self.table_components.as_ptr().add(table_row), | ||
ticks: Ticks { | ||
component_ticks: &mut *self.table_ticks.add(table_row), | ||
component_ticks: &mut *(&*self.table_ticks.add(table_row)).get(), | ||
change_tick: self.change_tick, | ||
last_change_tick: self.last_change_tick, | ||
}, | ||
|
@@ -558,7 +559,7 @@ impl<'w, T: Component> Fetch<'w> for WriteFetch<T> { | |
Mut { | ||
value: &mut *self.table_components.as_ptr().add(table_row), | ||
ticks: Ticks { | ||
component_ticks: &mut *self.table_ticks.add(table_row), | ||
component_ticks: &mut *(&*self.table_ticks.add(table_row)).get(), | ||
change_tick: self.change_tick, | ||
last_change_tick: self.last_change_tick, | ||
}, | ||
|
@@ -860,7 +861,7 @@ impl<'w, T: Component> Fetch<'w> for ChangeTrackersFetch<T> { | |
let column = tables[archetype.table_id()] | ||
.get_column(state.component_id) | ||
.unwrap(); | ||
self.table_ticks = column.get_ticks_mut_ptr().cast::<ComponentTicks>(); | ||
self.table_ticks = column.get_ticks_const_ptr(); | ||
} | ||
StorageType::SparseSet => self.entities = archetype.entities().as_ptr(), | ||
} | ||
|
@@ -871,8 +872,7 @@ impl<'w, T: Component> Fetch<'w> for ChangeTrackersFetch<T> { | |
self.table_ticks = table | ||
.get_column(state.component_id) | ||
.unwrap() | ||
.get_ticks_mut_ptr() | ||
.cast::<ComponentTicks>(); | ||
.get_ticks_const_ptr(); | ||
} | ||
|
||
#[inline] | ||
|
@@ -881,7 +881,7 @@ impl<'w, T: Component> Fetch<'w> for ChangeTrackersFetch<T> { | |
StorageType::Table => { | ||
let table_row = *self.entity_table_rows.add(archetype_index); | ||
ChangeTrackers { | ||
component_ticks: *self.table_ticks.add(table_row), | ||
component_ticks: (&*self.table_ticks.add(table_row)).clone(), | ||
marker: PhantomData, | ||
last_change_tick: self.last_change_tick, | ||
change_tick: self.change_tick, | ||
|
@@ -890,7 +890,7 @@ impl<'w, T: Component> Fetch<'w> for ChangeTrackersFetch<T> { | |
StorageType::SparseSet => { | ||
let entity = *self.entities.add(archetype_index); | ||
ChangeTrackers { | ||
component_ticks: *(*self.sparse_set).get_ticks(entity).unwrap(), | ||
component_ticks: (&*self.sparse_set).get_ticks(entity).cloned().unwrap(), | ||
marker: PhantomData, | ||
last_change_tick: self.last_change_tick, | ||
change_tick: self.change_tick, | ||
|
@@ -902,7 +902,7 @@ impl<'w, T: Component> Fetch<'w> for ChangeTrackersFetch<T> { | |
#[inline] | ||
unsafe fn table_fetch(&mut self, table_row: usize) -> Self::Item { | ||
ChangeTrackers { | ||
component_ticks: *self.table_ticks.add(table_row), | ||
component_ticks: (&*self.table_ticks.add(table_row)).clone(), | ||
marker: PhantomData, | ||
last_change_tick: self.last_change_tick, | ||
change_tick: self.change_tick, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the scenario that previously never dropped the first inserted component.