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

Bevy lets you use ScreenshotManager even if it won't work #11493

Open
banool opened this issue Jan 23, 2024 · 3 comments
Open

Bevy lets you use ScreenshotManager even if it won't work #11493

banool opened this issue Jan 23, 2024 · 3 comments
Labels
A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in C-Usability A simple quality-of-life change that makes Bevy easier to use

Comments

@banool
Copy link

banool commented Jan 23, 2024

Bevy version

0.12.1

Relevant system information

If you cannot get Bevy to build or run on your machine, please include:

  • the Rust version you're using (you can get this by running cargo --version)
    • cargo 1.75.0 (1d8b05cdd 2023-11-20)
  • the operating system or browser used, including its version
    • MacOS 14.2.1 (M1 ARM)

What you did

The docs for take_screenshot say this:

The given callback will eventually be called on one of the AsyncComputeTaskPool threads.

When I call take_screenshot it returns happily but the callback is never called. Same issue with save_screenshot_to_disk.

I'm setting up my systems with DefaultPlugins.build().disable::<WinitPlugin>(). I'm guessing that whatever is meant to come along later and make the screenshot happen never happens because I don't have a window.

What went wrong

While this is related to taking a screenshot in headless mode (#7163, #22), my main concern is with the API. If it's true that take_screenshot will never work without a window, one of the following should be true:

  • Calling screenshot_manager.take_screenshot should return an error immediately indicating that screenshots aren't possible bc x y z other plugins are missing.
  • It is impossible to get mut screenshot_manager: ResMut<ScreenshotManager> in the first place, I suppose bc the plugin is removed from the default set automatically if there is now window. Or maybe just because there is no event loop.

Additional information

I understand that without WinitPlugin there is no event loop and the update only runs once, so I wonder if there is a way to force the callback to be called later. It seems that just dropping the App instance doesn't make it happen. I guess it depends on whether taking a screenshot is expected to work without a window or not, and therefore if it relates to the window or the event loop.

@banool banool added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 23, 2024
@banool banool changed the title Bevy lets you use ScreenshotManager even if it won't not work Bevy lets you use ScreenshotManager even if it won't work Jan 23, 2024
@rparrett rparrett added A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in C-Usability A simple quality-of-life change that makes Bevy easier to use and removed C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 23, 2024
@rparrett
Copy link
Contributor

rparrett commented Jan 23, 2024

Yeah, we could do better here. I think that either of your suggestions could be made to work. The second seems like it would be a bit involved. Another option might be to add a warning around here:

if let Some(window) = extracted_windows.get_mut(&window) {
window.screenshot_func = Some(screenshot_func);
}

Out of curiosity, what are you using as take_screenshot's first parameter? Could the docs be made clearer that this needs a Window entity to work?

#22 is still open for a reason. Totally headless screenshots aren't possible yet. Even Bevy's CI uses a slightly janky setup of using a virtual framebuffer, initiating a screenshot, and just waiting a few seconds and hoping it was saved to the disk in time before exiting.

I don't believe there are any technical blockers. Just need a motivated person to make it work.

There are a few third party crates that also deal with screenshotting and one or more of them may be able to do this. I haven't looked in a while.

@rparrett rparrett added C-Regression Functionality that used to work but no longer does. Add a test for this! and removed C-Regression Functionality that used to work but no longer does. Add a test for this! labels Jan 23, 2024
@banool
Copy link
Author

banool commented Jan 23, 2024

Out of curiosity, what are you using as take_screenshot's first parameter? Could the docs be made clearer that this needs a Window entity to work?

I'm using main_window.single() from accepting this to the system: main_window: Query<Entity, With<PrimaryWindow>>. Surprisingly without Winit this still returns a window, so perhaps that's sort of the root cause issue here.

#22 is still open for a reason

Yeah for sure that's cool, I'm trying to do something similar for now too, or just run the API with access to a windowing system.

@rparrett
Copy link
Contributor

I'm using main_window.single() from accepting this to the system: main_window: Query<Entity, With>. Surprisingly without Winit this still returns a Window, so perhaps that's sort of the root cause issue here.

Ah, right. Thanks. WindowPlugin creates the PrimaryWindow automatically, and it seems like a web of various systems in bevy_winit and bevy_render are responsible for creating/associating "actual windows" and surfaces.

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 A-Windowing Platform-agnostic interface layer to run your app in C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

No branches or pull requests

2 participants