@@ -81,13 +81,7 @@ use crate::{
81
81
} ;
82
82
use alloc:: vec:: Vec ;
83
83
use bevy_platform:: sync:: atomic:: Ordering ;
84
- use core:: {
85
- fmt,
86
- hash:: Hash ,
87
- mem:: { self , MaybeUninit } ,
88
- num:: NonZero ,
89
- panic:: Location ,
90
- } ;
84
+ use core:: { fmt, hash:: Hash , mem, num:: NonZero , panic:: Location } ;
91
85
use log:: warn;
92
86
93
87
#[ cfg( feature = "serialize" ) ]
@@ -928,7 +922,7 @@ impl Entities {
928
922
pub ( crate ) unsafe fn mark_spawn_despawn ( & mut self , index : u32 , by : MaybeLocation , at : Tick ) {
929
923
// SAFETY: Caller guarantees that `index` a valid entity index
930
924
let meta = unsafe { self . meta . get_unchecked_mut ( index as usize ) } ;
931
- meta. spawned_or_despawned = MaybeUninit :: new ( SpawnedOrDespawned { by, at } ) ;
925
+ meta. spawned_or_despawned = SpawnedOrDespawned { by, at } ;
932
926
}
933
927
934
928
/// Increments the `generation` of a freed [`Entity`]. The next entity ID allocated with this
@@ -1006,7 +1000,7 @@ impl Entities {
1006
1000
Entity :: from_raw_and_generation ( row, meta. generation ) ,
1007
1001
& mut meta. location ,
1008
1002
) ;
1009
- meta. spawned_or_despawned = MaybeUninit :: new ( SpawnedOrDespawned { by, at } ) ;
1003
+ meta. spawned_or_despawned = SpawnedOrDespawned { by, at } ;
1010
1004
}
1011
1005
1012
1006
* free_cursor = 0 ;
@@ -1019,7 +1013,7 @@ impl Entities {
1019
1013
Entity :: from_raw_and_generation ( row, meta. generation ) ,
1020
1014
& mut meta. location ,
1021
1015
) ;
1022
- meta. spawned_or_despawned = MaybeUninit :: new ( SpawnedOrDespawned { by, at } ) ;
1016
+ meta. spawned_or_despawned = SpawnedOrDespawned { by, at } ;
1023
1017
}
1024
1018
}
1025
1019
@@ -1121,10 +1115,7 @@ impl Entities {
1121
1115
( meta. generation == entity. generation )
1122
1116
|| ( meta. location . archetype_id == ArchetypeId :: INVALID )
1123
1117
&& ( meta. generation == entity. generation . after_versions ( 1 ) ) )
1124
- . map ( |meta| {
1125
- // SAFETY: valid archetype or non-min generation is proof this is init
1126
- unsafe { meta. spawned_or_despawned . assume_init ( ) }
1127
- } )
1118
+ . map ( |meta| meta. spawned_or_despawned )
1128
1119
}
1129
1120
1130
1121
/// Returns the source code location from which this entity has last been spawned
@@ -1141,9 +1132,7 @@ impl Entities {
1141
1132
) -> ( MaybeLocation , Tick ) {
1142
1133
// SAFETY: caller ensures entity is allocated
1143
1134
let meta = unsafe { self . meta . get_unchecked ( entity. index ( ) as usize ) } ;
1144
- // SAFETY: caller ensures entities of this index were at least spawned
1145
- let spawned_or_despawned = unsafe { meta. spawned_or_despawned . assume_init ( ) } ;
1146
- ( spawned_or_despawned. by , spawned_or_despawned. at )
1135
+ ( meta. spawned_or_despawned . by , meta. spawned_or_despawned . at )
1147
1136
}
1148
1137
1149
1138
#[ inline]
@@ -1152,9 +1141,7 @@ impl Entities {
1152
1141
if meta. generation != EntityGeneration :: FIRST
1153
1142
|| meta. location . archetype_id != ArchetypeId :: INVALID
1154
1143
{
1155
- // SAFETY: non-min generation or valid archetype is proof this is init
1156
- let spawned_or_despawned = unsafe { meta. spawned_or_despawned . assume_init_mut ( ) } ;
1157
- spawned_or_despawned. at . check_tick ( change_tick) ;
1144
+ meta. spawned_or_despawned . at . check_tick ( change_tick) ;
1158
1145
}
1159
1146
}
1160
1147
}
@@ -1219,7 +1206,7 @@ struct EntityMeta {
1219
1206
/// The current location of the [`EntityRow`].
1220
1207
pub location : EntityLocation ,
1221
1208
/// Location of the last spawn, despawn or flush of this entity.
1222
- spawned_or_despawned : MaybeUninit < SpawnedOrDespawned > ,
1209
+ spawned_or_despawned : SpawnedOrDespawned ,
1223
1210
}
1224
1211
1225
1212
#[ derive( Copy , Clone , Debug ) ]
@@ -1233,7 +1220,10 @@ impl EntityMeta {
1233
1220
const EMPTY : EntityMeta = EntityMeta {
1234
1221
generation : EntityGeneration :: FIRST ,
1235
1222
location : EntityLocation :: INVALID ,
1236
- spawned_or_despawned : MaybeUninit :: uninit ( ) ,
1223
+ spawned_or_despawned : SpawnedOrDespawned {
1224
+ by : MaybeLocation :: caller ( ) ,
1225
+ at : Tick :: new ( 0 ) ,
1226
+ } ,
1237
1227
} ;
1238
1228
}
1239
1229
0 commit comments