bevy/crates
Arend van Beelen jr 5d110eb96e
Prevent black frames during startup (#9826)
# Objective

This PR addresses the issue where Bevy displays one or several black
frames before the scene is first rendered. This is particularly
noticeable on iOS, where the black frames disrupt the transition from
the launch screen to the game UI. I have written about my search to
solve this issue on the Bevy discord:
https://discord.com/channels/691052431525675048/1151047604520632352

While I can attest this PR works on both iOS and Linux/Wayland (and even
seems to resolve a slight flicker during startup with the latter as
well), I'm not familiar enough with Bevy to judge the full implications
of these changes. I hope a reviewer or tester can help me confirm
whether this is the right approach, or what might be a cleaner solution
to resolve this issue.

## Solution

I have moved the "startup phase" as well as the plugin finalization into
the `app.run()` function so those things finish synchronously before the
"main schedule" starts. I even move one frame forward as well, using
`app.update()`, to make sure the rendering has caught up with the state
of the finalized plugins as well.

I admit that part of this was achieved through trial-and-error, since
not doing the "startup phase" *before* `app.finish()` resulted in
panics, while not calling an extra `app.update()` didn't fully resolve
the issue.

What I *can* say, is that the iOS launch screen animation works in such
a way that the OS initiates the transition once the framework's
[`didFinishLaunching()`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622921-application)
returns, meaning app developers **must** finish setting up their UI
before that function returns. This is what basically led me on the path
to try to "finish stuff earlier" :)

## Changelog

### Changed

- The startup phase and the first frame are rendered synchronously when
calling `app.run()`, before the "main schedule" is started. This fixes
black frames during the iOS launch transition and possible flickering on
other platforms, but may affect initialization order in your
application.

## Migration Guide

Because of this change, the timing of the first few frames might have
changed, and I think it could be that some things one may expect to be
initialized in a system may no longer be. To be honest, I feel out of my
depth to judge the exact impact here.
2023-10-18 23:24:19 +00:00
..
bevy_a11y Various accessibility API updates. (#9989) 2023-10-02 21:22:52 +00:00
bevy_animation refactor: Change Option<With<T>> query params to Has<T> (#9959) 2023-10-02 01:21:41 +00:00
bevy_app Prevent black frames during startup (#9826) 2023-10-18 23:24:19 +00:00
bevy_asset Return an error when loading non-existent labels (#9751) 2023-10-15 18:36:51 +00:00
bevy_audio More ergonomic spatial audio (#9800) 2023-10-09 19:43:56 +00:00
bevy_core Change visibility of bevy::core::update_frame_count to pub (#10111) 2023-10-16 13:43:02 +00:00
bevy_core_pipeline Fix missing explicit lifetime name for copy_deferred_lighting_id name (#10128) 2023-10-15 14:37:53 +00:00
bevy_derive bevy_derive: Fix #[deref] breaking other attributes (#9551) 2023-08-28 17:36:18 +00:00
bevy_diagnostic Unify FixedTime and Time while fixing several problems (#8964) 2023-10-16 01:57:55 +00:00
bevy_dylib Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_dynamic_plugin Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_ecs add and fix shields in Readmes (#9993) 2023-10-15 00:52:31 +00:00
bevy_ecs_compile_fail_tests Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
bevy_encase_derive Bump Version after Release (#9106) 2023-07-10 21:19:27 +00:00
bevy_gilrs Unify FixedTime and Time while fixing several problems (#8964) 2023-10-16 01:57:55 +00:00
bevy_gizmos Deferred Renderer (#9258) 2023-10-12 22:10:38 +00:00
bevy_gltf Multiple Asset Sources (#9885) 2023-10-13 23:17:32 +00:00
bevy_hierarchy Fix some warnings shown in nightly (#10012) 2023-10-05 05:41:09 +00:00
bevy_input Change AxisSettings livezone default (#10090) 2023-10-12 17:58:32 +00:00
bevy_internal Multiple Asset Sources (#9885) 2023-10-13 23:17:32 +00:00
bevy_log Update tracy-client requirement from 0.15 to 0.16 (#9436) 2023-08-15 07:45:21 +00:00
bevy_macro_utils Update toml_edit requirement from 0.19 to 0.20 (#10058) 2023-10-09 11:55:16 +00:00
bevy_macros_compile_fail_tests bevy_derive: Fix #[deref] breaking other attributes (#9551) 2023-08-28 17:36:18 +00:00
bevy_math Automatic batching/instancing of draw commands (#9685) 2023-09-21 22:12:34 +00:00
bevy_mikktspace add and fix shields in Readmes (#9993) 2023-10-15 00:52:31 +00:00
bevy_pbr allow extensions to StandardMaterial (#7820) 2023-10-17 21:28:08 +00:00
bevy_ptr add and fix shields in Readmes (#9993) 2023-10-15 00:52:31 +00:00
bevy_reflect bevy_reflect: Fix dynamic type serialization (#10103) 2023-10-16 23:31:16 +00:00
bevy_reflect_compile_fail_tests Improve TypeUuid's derive macro error messages (#9315) 2023-10-02 12:42:01 +00:00
bevy_render allow extensions to StandardMaterial (#7820) 2023-10-17 21:28:08 +00:00
bevy_scene Correct Scene loader error description (#10161) 2023-10-17 17:58:35 +00:00
bevy_sprite allow extensions to StandardMaterial (#7820) 2023-10-17 21:28:08 +00:00
bevy_tasks add and fix shields in Readmes (#9993) 2023-10-15 00:52:31 +00:00
bevy_text Fix text2d view-visibility (#10100) 2023-10-13 19:14:31 +00:00
bevy_time Time: demote delta time clamping warning to debug (#10145) 2023-10-16 19:18:39 +00:00
bevy_transform Add system parameter for computing up-to-date GlobalTransforms (#8603) 2023-10-18 20:07:51 +00:00
bevy_ui Fix UI borders (#10078) 2023-10-13 17:17:16 +00:00
bevy_utils add and fix shields in Readmes (#9993) 2023-10-15 00:52:31 +00:00
bevy_window Various accessibility API updates. (#9989) 2023-10-02 21:22:52 +00:00
bevy_winit Prevent black frames during startup (#9826) 2023-10-18 23:24:19 +00:00