cargo-mobile icon indicating copy to clipboard operation
cargo-mobile copied to clipboard

Add egui example

Open zeerooth opened this issue 3 years ago • 9 comments

This example is (partially) functional right now, at least on Android, but there are a couple of bugs and QOL stuff that I think need to be addressed before merging this PR:

  • [x] ~~It is currently borked on desktop (unresponsive and resize fails with "Dropped frame with error: The underlying surface has changed, and therefore the swap chain must be updated")~~
  • [ ] iOS tests (I don't have such device, can somebody with one test this, pretty please? :3)
  • [ ] Virtual keyboard not being displayed on text fields (may need to be fixed upstream) (update: yeah, to handle the virtual keyboard input, composition events for Android need to be implemented in winit first, therefore this is currently unfixable)
  • [x] ~~Weird workaround with waiting for NativeActivity~~
  • [x] ~~Weird resolution at the start, which is fixed when rotating the screen (edit: I found out that the resolution is actually set correctly, but the scale_factor of winit::Window is incorrectly reported as 1.0 at the start. This was fixed in this PR for winit but we still need to wait for a full winit release and for new winit version to be changed in egui_winit soo untill that I guess this PR is blocked :x )~~ (fixed!)
  • [x] ~~Crash when leaving the app in the background~~
  • [x] ~~Status bar overlays the app which leads to some content not being interactable~~ (fixed by enabling fullscreen by default)
  • [x] ~~Update egui_wgpu_backend version when a new one is published with egui 0.15~~

zeerooth avatar Oct 25 '21 18:10 zeerooth

I think this PR is ready to be merged now - I still haven't tested this on iOS (because I lack the capacity to) and the virtual keyboard is not working, but it's dependant or future changes in winit. However, the rest of the functionalities in the demo seem to be working fine!

zeerooth avatar Jan 03 '22 20:01 zeerooth

iOS tests (I don't have such device, can somebody with one test this, pretty please? :3)

Here I go!

Oh...

error: Only Windows, Mac OS, Linux, *BSD and Haiku and Wasm32 are currently supported
   --> /Users/francesca/.cargo/registry/src/github.com-1ecc6299db9ec823/webbrowser-0.5.5/src/lib.rs:232:1
    |
232 | compile_error!("Only Windows, Mac OS, Linux, *BSD and Haiku and Wasm32 are currently supported");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It doesn't look there's any upstream traction on this. If you'd like, you can just mark iOS as unsupported with a comment explaining why: https://github.com/BrainiumLLC/cargo-mobile/blob/c75c985c80c1ded70f93293f5bd38812375d27af/src/apple/config/mod.rs#L74-L75

francesca64 avatar Feb 04 '22 01:02 francesca64

iOS tests (I don't have such device, can somebody with one test this, pretty please? :3)

Here I go!

Oh...

error: Only Windows, Mac OS, Linux, *BSD and Haiku and Wasm32 are currently supported
   --> /Users/francesca/.cargo/registry/src/github.com-1ecc6299db9ec823/webbrowser-0.5.5/src/lib.rs:232:1
    |
232 | compile_error!("Only Windows, Mac OS, Linux, *BSD and Haiku and Wasm32 are currently supported");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It doesn't look there's any upstream traction on this. If you'd like, you can just mark iOS as unsupported with a comment explaining why:

https://github.com/BrainiumLLC/cargo-mobile/blob/c75c985c80c1ded70f93293f5bd38812375d27af/src/apple/config/mod.rs#L74-L75

I managed to fix that by disabing the default features for egui-winit (I seems they are not required for the demo so it should be safe to do so) and the build for aarch64-apple-ios managed to pass that step

Can you please try again now @francesca64 ?

zeerooth avatar Feb 04 '22 21:02 zeerooth

Now it builds fine, but crashes immediately:

-[MTLCompileOptionsInternal setPreserveInvariance:]: unrecognized selector sent to instance 0x2811be040

This originates down in the metal-rs crate: https://github.com/gfx-rs/metal-rs/blob/140c8f4e39001ae154f153ffc767da6c0c9d7f06/src/library.rs#L572-L575

The device I'm testing on is running iOS 13.1.2, which should support that, as far as I can tell.

This was added to wgpu quite recently: gfx-rs/wgpu#2372

The equivalent logic in MoltenVK dynamically checks if the selector is supported, as opposed to checking the version like in the wgpu PR, which could be significant: https://github.com/KhronosGroup/MoltenVK/blob/101ea9eec158717c38c448d313d3c6452f8b327c/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm#L3781-L3783

@ArthurKValladares can you try to run this too? I'm curious if this is device-dependent.

francesca64 avatar Feb 04 '22 23:02 francesca64

Runs fine on my device on iOS 15.2.1.

ArthurKValladares avatar Feb 05 '22 00:02 ArthurKValladares

Now it builds fine, but crashes immediately:

-[MTLCompileOptionsInternal setPreserveInvariance:]: unrecognized selector sent to instance 0x2811be040

This originates down in the metal-rs crate: https://github.com/gfx-rs/metal-rs/blob/140c8f4e39001ae154f153ffc767da6c0c9d7f06/src/library.rs#L572-L575

The device I'm testing on is running iOS 13.1.2, which should support that, as far as I can tell.

This was added to wgpu quite recently: gfx-rs/wgpu#2372

The equivalent logic in MoltenVK dynamically checks if the selector is supported, as opposed to checking the version like in the wgpu PR, which could be significant: https://github.com/KhronosGroup/MoltenVK/blob/101ea9eec158717c38c448d313d3c6452f8b327c/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm#L3781-L3783

@ArthurKValladares can you try to run this too? I'm curious if this is device-dependent.

Thanks for investigating this, I definitely wouldn't have figured out the root cause of that issue.

What can we do about it though? Since that fix has been added to wgpu recently, could you please try using the wgpu from the master branch instead of the latest 0.12 release on creates.io that doesn't contain that fix and see if the template works with it?

zeerooth avatar Feb 11 '22 19:02 zeerooth