1
+ #[ cfg( feature = "track_location" ) ]
2
+ use crate :: change_detection:: MaybeLocation ;
1
3
use crate :: {
2
4
system:: { Command , SystemBuffer , SystemMeta } ,
3
5
world:: { DeferredWorld , World } ,
4
6
} ;
7
+
5
8
use alloc:: { boxed:: Box , vec:: Vec } ;
6
9
use bevy_ptr:: { OwningPtr , Unaligned } ;
7
10
use core:: {
@@ -29,7 +32,6 @@ struct CommandMeta {
29
32
// entities/components/resources, and it's not currently possible to parallelize these
30
33
// due to mutable [`World`] access, maximizing performance for [`CommandQueue`] is
31
34
// preferred to simplicity of implementation.
32
- #[ derive( Default ) ]
33
35
pub struct CommandQueue {
34
36
// This buffer densely stores all queued commands.
35
37
//
@@ -39,6 +41,21 @@ pub struct CommandQueue {
39
41
pub ( crate ) bytes : Vec < MaybeUninit < u8 > > ,
40
42
pub ( crate ) cursor : usize ,
41
43
pub ( crate ) panic_recovery : Vec < MaybeUninit < u8 > > ,
44
+ #[ cfg( feature = "track_location" ) ]
45
+ pub ( crate ) caller : MaybeLocation ,
46
+ }
47
+
48
+ impl Default for CommandQueue {
49
+ #[ track_caller]
50
+ fn default ( ) -> Self {
51
+ Self {
52
+ bytes : Default :: default ( ) ,
53
+ cursor : Default :: default ( ) ,
54
+ panic_recovery : Default :: default ( ) ,
55
+ #[ cfg( feature = "track_location" ) ]
56
+ caller : MaybeLocation :: caller ( ) ,
57
+ }
58
+ }
42
59
}
43
60
44
61
/// Wraps pointers to a [`CommandQueue`], used internally to avoid stacked borrow rules when
@@ -57,9 +74,13 @@ pub(crate) struct RawCommandQueue {
57
74
// So instead, the manual impl just prints the length of vec.
58
75
impl Debug for CommandQueue {
59
76
fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
60
- f. debug_struct ( "CommandQueue" )
61
- . field ( "len_bytes" , & self . bytes . len ( ) )
62
- . finish_non_exhaustive ( )
77
+ let mut binding = f. debug_struct ( "CommandQueue" ) ;
78
+ binding. field ( "len_bytes" , & self . bytes . len ( ) ) ;
79
+
80
+ #[ cfg( feature = "track_location" ) ]
81
+ binding. field ( "caller" , & self . caller . into_option ( ) ) ;
82
+
83
+ binding. finish_non_exhaustive ( )
63
84
}
64
85
}
65
86
@@ -311,6 +332,9 @@ impl RawCommandQueue {
311
332
impl Drop for CommandQueue {
312
333
fn drop ( & mut self ) {
313
334
if !self . bytes . is_empty ( ) {
335
+ #[ cfg( feature = "track_location" ) ]
336
+ warn ! ( "CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply? caller:{:?}" , self . caller. into_option( ) ) ;
337
+ #[ cfg( not( feature = "track_location" ) ) ]
314
338
warn ! ( "CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply?" ) ;
315
339
}
316
340
// SAFETY: A reference is always a valid pointer
0 commit comments