Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Increment FrameCount in CoreStage::Last. #7477

Conversation

stephenmartindale
Copy link
Contributor

Objective

During testing, I observed that the FrameCount resource (bevy_core) was being incremented by FrameCountPlugin non-deterministically, during update, subject to the whims of the execution order.

The effect was that the counter could and did change while a frame was still in flight, while user-systems were still executing.

Solution

I have delayed the incrementing of the FrameCount resource to CoreStage::Last. The resource was described in the documentation as "a count of rendered frames" and, after my change, it actually will match that description.

Changes

  • CoreStage::Last was chosen so that the counter will be 0 during all earlier stages of the very first execution of the schedule.
  • Documentation added declaring when the counter is incremented.
  • Hint added, directing users towards u32::wrapping_sub() because integer overflow is reasonable to expect.

Note

Even though this change might have a short time-to-live in light of the upcoming Stageless changes, I think this is worthwhile – at least as an in-code reminder that this counter should behave predictably.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Diagnostics Logging, crash handling, error reporting and performance analysis A-Time Involves time keeping and reporting labels Feb 2, 2023
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it C-Docs An addition or correction to our documentation labels Feb 2, 2023
@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Feb 2, 2023
# Objective

During testing, I observed that the `FrameCount` resource (`bevy_core`) was being incremented by `FrameCountPlugin` non-deterministically, during update, subject to the whims of the execution order.

The effect was that the counter could and did change while a frame was still in flight, while user-systems were still executing.

## Solution

I have delayed the incrementing of the `FrameCount` resource to `CoreStage::Last`. The resource was described in the documentation as "*a count of rendered frames*" and, after my change, it actually will match that description.

## Changes

- `CoreStage::Last` was chosen so that the counter will be `0` during all earlier stages of the very first execution of the schedule.
- Documentation added declaring *when* the counter is incremented.
- Hint added, directing users towards `u32::wrapping_sub()` because integer overflow is reasonable to expect.

## Note

Even though this change might have a short time-to-live in light of the upcoming *Stageless* changes, I think this is worthwhile – at least as an in-code reminder that this counter should behave predictably.
@bors bors bot changed the title Increment FrameCount in CoreStage::Last. [Merged by Bors] - Increment FrameCount in CoreStage::Last. Feb 2, 2023
@bors bors bot closed this Feb 2, 2023
@stephenmartindale stephenmartindale deleted the deterministic-frame-count branch February 2, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-Time Involves time keeping and reporting C-Bug An unexpected or incorrect behavior C-Docs An addition or correction to our documentation S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants