Skip to content

Commit ef7bce8

Browse files
MushineLamentMushine Lament
andauthored
systemstate support commands track location (#22353)
# Objective When acquiring Commands within SystemState, it causes incorrect tracking of MaybeLocation in CommandQueue, mistakenly pointing to the FromWorld trait implementation. ## Solution Add track_caller support for the Commands SystemParam. ## Testing I only verified whether tracking is present, but did not perform any tests. Co-authored-by: Mushine Lament <[email protected]>
1 parent 61fdae2 commit ef7bce8

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const _: () = {
130130

131131
type Item<'w, 's> = Commands<'w, 's>;
132132

133+
#[track_caller]
133134
fn init_state(world: &mut World) -> Self::State {
134135
FetchState {
135136
state: <__StructFieldsAlias<'_, '_> as bevy_ecs::system::SystemParam>::init_state(
@@ -193,6 +194,7 @@ const _: () = {
193194
}
194195

195196
#[inline]
197+
#[track_caller]
196198
unsafe fn get_param<'w, 's>(
197199
state: &'s mut Self::State,
198200
system_meta: &bevy_ecs::system::SystemMeta,

crates/bevy_ecs/src/system/function_system.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ all_tuples!(
286286

287287
impl<Param: SystemParam> SystemState<Param> {
288288
/// Creates a new [`SystemState`] with default state.
289+
#[track_caller]
289290
pub fn new(world: &mut World) -> Self {
290291
let mut meta = SystemMeta::new::<Param>();
291292
meta.last_run = world.change_tick().relative_to(Tick::MAX);
@@ -362,6 +363,7 @@ impl<Param: SystemParam> SystemState<Param> {
362363

363364
/// Retrieve the mutable [`SystemParam`] values.
364365
#[inline]
366+
#[track_caller]
365367
pub fn get_mut<'w, 's>(&'s mut self, world: &'w mut World) -> SystemParamItem<'w, 's, Param> {
366368
self.validate_world(world.id());
367369
// SAFETY: World is uniquely borrowed and matches the World this SystemState was created with.
@@ -421,6 +423,7 @@ impl<Param: SystemParam> SystemState<Param> {
421423
/// access is safe in the context of global [`World`] access. The passed-in [`World`] _must_ be the [`World`] the [`SystemState`] was
422424
/// created with.
423425
#[inline]
426+
#[track_caller]
424427
pub unsafe fn get_unchecked<'w, 's>(
425428
&'s mut self,
426429
world: UnsafeWorldCell<'w>,
@@ -435,6 +438,7 @@ impl<Param: SystemParam> SystemState<Param> {
435438
/// access is safe in the context of global [`World`] access. The passed-in [`World`] _must_ be the [`World`] the [`SystemState`] was
436439
/// created with.
437440
#[inline]
441+
#[track_caller]
438442
unsafe fn fetch<'w, 's>(
439443
&'s mut self,
440444
world: UnsafeWorldCell<'w>,

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ unsafe impl<T: SystemBuffer> SystemParam for Deferred<'_, T> {
13361336
type State = SyncCell<T>;
13371337
type Item<'w, 's> = Deferred<'s, T>;
13381338

1339+
#[track_caller]
13391340
fn init_state(world: &mut World) -> Self::State {
13401341
SyncCell::new(T::from_world(world))
13411342
}
@@ -2171,6 +2172,7 @@ macro_rules! impl_system_param_tuple {
21712172
type Item<'w, 's> = ($($param::Item::<'w, 's>,)*);
21722173

21732174
#[inline]
2175+
#[track_caller]
21742176
fn init_state(world: &mut World) -> Self::State {
21752177
($($param::init_state(world),)*)
21762178
}
@@ -2216,6 +2218,7 @@ macro_rules! impl_system_param_tuple {
22162218
}
22172219

22182220
#[inline]
2221+
#[track_caller]
22192222
unsafe fn get_param<'w, 's>(
22202223
state: &'s mut Self::State,
22212224
system_meta: &SystemMeta,

crates/bevy_ecs/src/world/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,7 @@ pub trait FromWorld {
38293829

38303830
impl<T: Default> FromWorld for T {
38313831
/// Creates `Self` using [`default()`](`Default::default`).
3832+
#[track_caller]
38323833
fn from_world(_world: &mut World) -> Self {
38333834
T::default()
38343835
}

0 commit comments

Comments
 (0)