Skip to content

Commit 7d4cb70

Browse files
RiskLoveheshuai
andauthored
BugFix: Archetype grow with defferent size. (#930)
Co-authored-by: heshuai <heshuai@163.com>
1 parent 12f29bd commit 7d4cb70

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crates/bevy_ecs/src/core/archetype.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ impl Archetype {
272272
fn grow(&mut self, increment: usize) {
273273
unsafe {
274274
let old_count = self.len;
275-
let count = old_count + increment;
275+
let new_capacity = self.capacity() + increment;
276276
self.entities.resize(
277-
self.entities.len() + increment,
277+
new_capacity,
278278
Entity {
279279
id: u32::MAX,
280280
generation: u32::MAX,
@@ -284,7 +284,7 @@ impl Archetype {
284284
for type_state in self.state.values_mut() {
285285
type_state
286286
.component_flags
287-
.resize_with(count, ComponentFlags::empty);
287+
.resize_with(new_capacity, ComponentFlags::empty);
288288
}
289289

290290
let old_data_size = mem::replace(&mut self.data_size, 0);
@@ -294,7 +294,7 @@ impl Archetype {
294294
let ty_state = self.state.get_mut(&ty.id).unwrap();
295295
old_offsets.push(ty_state.offset);
296296
ty_state.offset = self.data_size;
297-
self.data_size += ty.layout.size() * count;
297+
self.data_size += ty.layout.size() * new_capacity;
298298
}
299299
let new_data = if self.data_size == 0 {
300300
NonNull::dangling()

0 commit comments

Comments
 (0)