bevyengine / bevyengine/bevy

`Deferred::apply` runs even if the system never ran.

Open
#21,549 1 comment 0 reactions 0 assignees View on GitHub
A-ECS C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version and features

- Main @ fcd5c265

## What you did

```rust
// My app does not include the diagnostics plugin, so the DiagnosticsBuffer within Diagnostics will fail to apply.

fn my_optional_diagnostics_system(mut diagnostics: If) {
// I only want these measurements to be sent when diagnostics exist.
}
```

## What went wrong

The SystemBuffer in DiagnosticsBuffer gets applied, resulting in a panic since the DiagnosticsStore does not exist.

While the DiagnosticsBuffer probably should avoid panicking in this case, we also probably shouldn't be applying `Deferred` if the system never ran! This is most visible using the `If` type to automatically skip systems when the DiagnosticsStore is missing.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the optional diagnostics example and trace Deferred::apply when the If-wrapped system is skipped. Inspect the interaction between If, DiagnosticsBuffer, and the scheduler; done means skipped systems no longer apply deferred state, while systems that run still apply it without causing the reported panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.