Android issue collection

Aperta
#26,282 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
15/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
android, rust

Direzione di ricerca

The report groups several Android problems across winit, GameActivity touch handling, Bevy threading, rendering, background CPU use, timing, picking, audio, and lifecycle events. Start by choosing one symptom and tracing its linked issue or Bevy entry point; the report gives device and Android version details but no specific Bevy files or tests. Done would require a separately scoped issue with a reproducible case and a fix validated on Android.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-Windowing C-Bug C-Performance C-Tracking-Issue O-Android S-Needs-Review

I discovered these issues on 2 phones with bevy v0.19.* and I think all of them persist in
v0.20.*.

Devices:

  • Samsung Galaxy A33 (Android 16 | Display 60Hz/90Hz)
  • Samsung Galaxy S20 (Android 13 | Display 60Hz/120Hz)

Solving or patching the issues below I could reach CPU and GPU usages that are somewhat in range of
the app in Godot but I used GPUWatch from Samsung and I don't know how accurate this is.

ndk: 29.0.14206865
minSdk: 29
targetSdk: 37
GPU backend: Vulkan

winit

Android RecreationAttempt failure: https://github.com/rust-windowing/winit/issues/3325
There is a patch for this issue that I use: https://github.com/rib/winit/commit/c28e425214e82bdb86dcdf89c9488554a18e24b2


Crash when there are more than 8 touches (GameActivity)
- https://github.com/bevyengine/bevy/issues/16798
- https://github.com/rust-mobile/android-activity/issues/175
- Reopen: https://github.com/rust-mobile/android-activity/issues/253
Workaround patch: https://github.com/Johannes0021/android-activity/commit/d31a501a252a2dbb359bd7b4673128017aab7746

bevy

Allow AndroidApp handle activity recreation: https://github.com/bevyengine/bevy/pull/26015
After this fix the LogPlugin can be disabled in subsequent recreations in DefaultPlugins to
prevent error logging.

static FIRST_BUILD: AtomicBool = AtomicBool::new(true);

if !FIRST_BUILD.swap(false, Ordering::Relaxed) {
    plugins = plugins.disable::<LogPlugin>();
}

multi_threaded feature:

Setting device fps to 90(A33) or 120(S20) even for simple apps the fps are unstable which ist not a nice experience.
Single-threaded it runs smooth like butter. I know that there is overhead using multiple threads and
that mobile phones are low power devices that aggressively save power, but I can't believe that my
app runs single-threaded no sweat and multi-threaded it's lagging.


I noticed that MSAA uses a lot of GPU power which makes sense but I was very confused that it is
enabled by default and I did not know why my GPU usage was so high.
Rendering on native resolution, a simple app can't hit 60fps (GPU maxed out).


The app is killed in the background because of CPU usage (~after 1h in bg). I had to disable the audio feature in
bevy, because the audio thread was still using too much CPU in the background.
Solved in a workaround replacement plugin for bevy_audio: https://github.com/Johannes0021/bevy_mod_audio

After that, I had to fix the remaining CPU usage with:

app.insert_resource(WinitSettings::game())
    .add_systems(Update, update_winit_settings_on_lifecycle);

// ...

fn update_winit_settings_on_lifecycle(
    mut winit_settings: ResMut<WinitSettings>,
    mut lifecycle_messages: MessageReader<AppLifecycle>,
) {
    for msg in lifecycle_messages.read() {
        match msg {
            AppLifecycle::Suspended => {
                *winit_settings = WinitSettings {
                    unfocused_mode: bevy::winit::UpdateMode::Reactive {
                        wait: Duration::from_secs(1),
                        react_to_device_events: false,
                        react_to_user_events: false,
                        react_to_window_events: false,
                    },
                    ..WinitSettings::game()
                };
            }

            AppLifecycle::Running => *winit_settings = WinitSettings::game(),

            AppLifecycle::Idle | AppLifecycle::WillSuspend | AppLifecycle::WillResume => (),
        }
    }
}

I also noticed that the delta time is very unstable and causes animations to stutter. If I force the
delta time to 60 fps, the animations are smooth. I think there may be a problem with the delta time
calculation. I wrote a small plugin that tries to work around this problem by smoothing the delta
time. It's a bit rough: https://github.com/Johannes0021/bevy_mod_time_smoothing.git


This greatly improves GPU performance:

DefaultPlugins.set(RenderPlugin {
    render_creation: RenderCreation::Automatic(Box::new(WgpuSettings {
        priority: WgpuSettingsPriority::WebGL2,
        limits: WgpuLimits::downlevel_webgl2_defaults()
            .using_resolution(WgpuLimits::default()),
        ..default()
    })),
    ..default()
})

I think I also had issues with bevy_picking with touch input being cancelled and reported by winit but without receiving a release or drag out event.
I wrote a rough workaround by tracking the first finger pressed state and sprite picking events.
It would also be handy if bevy would expose a PointerOrder resource or else that assigns the finger an index somewhat like: https://github.com/Johannes0021/bevy_mod_input/blob/main/src/pointer_order.rs


In the past i had an issue with rodio that is still present: https://github.com/RustAudio/rodio/issues/836
Solved in a workaround replacement plugin for bevy_audio: https://github.com/Johannes0021/bevy_mod_audio


AppLifecycle: https://docs.rs/bevy/latest/bevy/window/enum.AppLifecycle.html

I think WillSuspend, WillResume, are never sent or received.


WinitSettings: https://docs.rs/bevy/latest/bevy/winit/struct.WinitSettings.html
I think the fn https://docs.rs/bevy/latest/bevy/winit/struct.WinitSettings.html#method.mobile
is misleading. It tries to pin the fps to 60. This might be okay for static apps but on Android
which forces VSync, this causes single frame drops on 60 fps and is unplayable on for example 90fps.

Lingua principale
Rust
Stelle
49.7k
Fork
5k
Merge medio
3g 19h
PR unite (30g)
134

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bevyengine/bevy

Tutte le issue di bevyengine/bevy

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.