Skip to content

Fix headless_renderer example and mention Screenshot.#19598

Merged
alice-i-cecile merged 3 commits intobevyengine:mainfrom
kpreid:headless
Jun 12, 2025
Merged

Fix headless_renderer example and mention Screenshot.#19598
alice-i-cecile merged 3 commits intobevyengine:mainfrom
kpreid:headless

Conversation

@kpreid
Copy link
Contributor

@kpreid kpreid commented Jun 12, 2025

Objective

  • Makes headless_renderer example work instead of exiting without effect.
  • Guides users who actually just need Screenshot to use that instead.

This PR was inspired by my own efforts to do headless rendering, in which the complexity of the headless_renderer example was a distraction, and this comment from #12478 (comment) :

The example added in #13006 would benefit from this change: be sure to clean it up when tackling this work :)

That “cleanup” was not done, and I thought to do it, but it seems to me that using Screenshot (in its current form) in the example would not be correct, because — if I understand correctly — the example is trying to, potentially, capture many consecutive frames, whereas Screenshot by itself gives no means to capture multiple frames without gaps or duplicates. But perhaps I am wrong (the code is complex and not clearly documented), or perhaps that feature isn’t worth preserving. In that case, let me know and I will revise this PR.

Solution

  • Added exit_condition: bevy::window::ExitCondition::DontExit
  • Added a link to Screenshot in the crate documentation.

Testing

  • Ran the example and confirmed that it now writes an image file and then exits.

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy A-Rendering Drawing game state to the screen labels Jun 12, 2025
@alice-i-cecile alice-i-cecile added C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jun 12, 2025
@alice-i-cecile
Copy link
Member

But perhaps I am wrong (the code is complex and not clearly documented), or perhaps that feature isn’t worth preserving. In that case, let me know and I will revise this PR.

The feature is definitely worth preserving: that's important for machine learning applications, and some forms of testing.

I'm not familiar enough to know if we could reuse Screenshot to do this perfectly and more simply, but this is a clear improvement over the current state of things. As a result, merging :)

@alice-i-cecile alice-i-cecile enabled auto-merge June 12, 2025 17:54
.set(WindowPlugin {
primary_window: None,
// Don’t automatically exit due to having no windows.
exit_condition: bevy::window::ExitCondition::DontExit,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what makes it exit then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very much worth explaining, so I added a comment about that. The code explicitly generates an AppExit event.

I didn’t see any information in the contribution guide about force-push/rebase/squash preferences, so I added an extra commit with that comment, but I would personally rather rebase to 2 commits. Please let me know what is preferred.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have strong preferences about git workflows (primarily to reduce the barrier of entry), but I personally find that rebasing / force pushing sucks on Github because it risks stranding comments and generating nonsense notifications.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 12, 2025
@alice-i-cecile alice-i-cecile removed this pull request from the merge queue due to a manual request Jun 12, 2025
@alice-i-cecile alice-i-cecile added D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it D-Trivial Nice and easy! A great choice to get started with Bevy labels Jun 12, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 12, 2025
@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 12, 2025
Merged via the queue into bevyengine:main with commit 1dfe83b Jun 12, 2025
35 of 36 checks passed
@kpreid kpreid deleted the headless branch January 5, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants