Skip to content
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
12 changes: 11 additions & 1 deletion crates/bevy_diagnostic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,17 @@ impl SystemBuffer for DiagnosticsBuffer {
_system_meta: &bevy_ecs::system::SystemMeta,
world: &mut bevy_ecs::world::World,
) {
let mut diagnostics = world.resource_mut::<DiagnosticsStore>();
let Some(mut diagnostics) = world.get_resource_mut::<DiagnosticsStore>() else {
// `SystemBuffer::apply` is called even if the system never runs. If a user uses
// `If<Diagnostics>`, this buffer will be applied even if we are missing
// `DiagnosticsStore`. So be permissive to allow these cases. See
// https://github.com/bevyengine/bevy/issues/21549 for more.

// Clear the buffer since we have nowhere to put those metrics and we don't want them to
// grow without bound.
self.0.clear();
return;
};
for (path, measurement) in self.0.drain() {
if let Some(diagnostic) = diagnostics.get_mut(&path) {
diagnostic.add_measurement(measurement);
Expand Down