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

Prevent creation of superfluous empty table #16935

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion crates/bevy_ecs/src/storage/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ impl Tables {
component_ids: &[ComponentId],
components: &Components,
) -> TableId {
if component_ids.is_empty() {
return TableId::empty();
}

let tables = &mut self.tables;
let (_key, value) = self
.table_ids
Expand Down Expand Up @@ -816,14 +820,26 @@ mod tests {
component::{Component, Components, Tick},
entity::Entity,
ptr::OwningPtr,
storage::{Storages, TableBuilder, TableRow},
storage::{Storages, TableBuilder, TableId, TableRow, Tables},
};
#[cfg(feature = "track_change_detection")]
use core::panic::Location;

#[derive(Component)]
struct W<T>(T);

#[test]
fn only_one_empty_table() {
let components = Components::default();
let mut tables = Tables::default();

let component_ids = &[];
// SAFETY: component_ids is empty, so we know it cannot reference invalid component IDs
let table_id = unsafe { tables.get_id_or_insert(component_ids, &components) };

assert_eq!(table_id, TableId::empty());
}

#[test]
fn table() {
let mut components = Components::default();
Expand Down
Loading