nativeshell / examples

Other
64 stars 7 forks source link

Crash when pressing Long Running Task, followed by Open in New Window #7

Closed nyanpasu64 closed 3 years ago

nyanpasu64 commented 3 years ago

I'm running this repo, latest main d385acefcc2405ddb863f79e3ccdb4479891008c, on Linux.

If I press the "Long Running Task" button one or more times, then either wait for it to finish or not, then "Open in New Window", the app will usually segfault instead of opening a window.

Stack trace is as follows (sadly it's a bit useless since libflutter_linux_gtk.so has no symbols):

``` (gdb) bt #0 0x00007ffff0eef4d8 in () at /usr/lib/libnvidia-glcore.so.465.31 #1 0x00007ffff0fb15f1 in () at /usr/lib/libnvidia-glcore.so.465.31 #2 0x00007ffff0fbaabb in () at /usr/lib/libnvidia-glcore.so.465.31 #3 0x00007ffff0bf3556 in () at /usr/lib/libnvidia-glcore.so.465.31 #4 0x00007ffff77f06cd in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #5 0x00007ffff775a31f in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #6 0x00007ffff76e9fea in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #7 0x00007ffff76e9ecb in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #8 0x00007ffff76dd072 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #9 0x00007ffff76dcb5e in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #10 0x00007ffff76dd319 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #11 0x00007ffff74d5ded in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #12 0x00007ffff74a19a7 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #13 0x00007ffff74a2a58 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #14 0x00007ffff78ae12d in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #15 0x00007ffff78af068 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #16 0x00007ffff78b02b6 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #17 0x00007ffff78ae7c5 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #18 0x00007ffff78ae408 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #19 0x00007ffff78c5149 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #20 0x00007ffff74a9afc in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #21 0x00007ffff749651a in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #22 0x00007ffff73fea85 in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #23 0x00007ffff73febed in () at /code/nativeshell-examples/target/debug/lib/libflutter_linux_gtk.so #24 0x00007ffff51716b4 in () at /usr/lib/libglib-2.0.so.0 #25 0x00007ffff5171015 in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0 #26 0x00007ffff51c4b99 in () at /usr/lib/libglib-2.0.so.0 #27 0x00007ffff5170693 in g_main_loop_run () at /usr/lib/libglib-2.0.so.0 #28 0x00007ffff590126f in gtk_main () at /usr/lib/libgtk-3.so.0 #29 0x00005555559bc637 in gtk::auto::functions::main () at /home/nyanpasu64/.cargo/registry/src/github.com-1ecc6299db9ec823/gtk-0.9.2/src/auto/functions.rs:314 #30 0x00005555558a4aab in nativeshell::shell::platform::platform_impl::run_loop::PlatformRunLoop::run (self=0x555555c1a2f0) at /home/nyanpasu64/.cargo/registry/src/github.com-1ecc6299db9ec823/nativeshell-0.1.6/src/shell/platform/linux/run_loop.rs:63 #31 0x00005555558e781d in nativeshell::shell::run_loop::RunLoop::run (self=0x555555c1a0f0) at /home/nyanpasu64/.cargo/registry/src/github.com-1ecc6299db9ec823/nativeshell-0.1.6/src/shell/run_loop.rs:41 #32 0x00005555555feade in nativeshell_examples::main () at src/main.rs:39 ```

I'm not sure if it's a NativeShell bug, example bug, Flutter bug, or Nvidia proprietary driver issue. (My GPU is awful, and the driver is awful too, but it's all I have to use. Adding/removing nvidia-drm.modeset=1 to the kernel command line didn't affect this bug.)

Flutter version:

Flutter 2.3.0-17.0.pre.386 • channel master • https://github.com/flutter/flutter.git Framework • revision c6cd8a60c3 (17 hours ago) • 2021-06-16 22:14:02 -0400 Engine • revision df3aa14215 Tools • Dart 2.14.0 (build 2.14.0-216.0.dev)

System info:

Operating System: Arch Linux KDE Plasma Version: 5.22.1 KDE Frameworks Version: 5.83.0 Qt Version: 5.15.2 Kernel Version: 5.12.10-zen1-1-zen (64-bit) Graphics Platform: X11 Processors: 12 × AMD Ryzen 5 5600X 6-Core Processor Memory: 15.6 GiB of RAM Graphics Processor: NVIDIA GeForce GT 730/PCIe/SSE2

knopp commented 3 years ago

I haven't tested it with nVidia driver in a while. I reported similar issue that causes crash on linux when opening new window (that happened in nVidia driver) here: https://github.com/flutter/flutter/issues/82353 . But it has been fixed in the meanwhile.

Sadly the symbols are all gone in regular engine builds, and even with symbols the crash might have been caused by something seemingly unrelated that has happened before. Still, I'll try to reproduce this with nVidia driver over the weekend.

knopp commented 3 years ago

Sorry, my bad, the actual issue was this: https://github.com/flutter/engine/pull/26070

It causes a thread terminating when opening new window. But it also only happened with lldb attached. So it might not be related to your issue.

nyanpasu64 commented 3 years ago

For me, the issue occurs in both cargo run and with a debugger attached.

I also got a rendering issue (though I cannot reproduce it reliably):

Screenshot_20210617_130329

Screenshot_20210617_130334

Not sure if it's my terrible potato GPU, or Nvidia's drivers, that's causing the rendering errors.

knopp commented 3 years ago

That really looks like a skia/gpu issue. Really not sure what to do about that.

knopp commented 3 years ago

I seem to be able to reproduce the crash. Looks like a possible regression in Flutter engine. The artifacts might be related. I'll look into this.

nyanpasu64 commented 3 years ago

Is there some sort of uninitialized memory being used, or a wild pointer write, in either Flutter or the nativeshell glue code (or perhaps the proprietary nvidia drivers, but I don't know)?

I've noticed that if I run valgrind target/release/nativeshell_examples:

Sadly RUSTFLAGS=-Zsanitizer=address cargo +nightly run -Zbuild-std --target x86_64-unknown-linux-gnu didn't help because the crash occurred in a libflutter_linux_gtk.so call stack. I did verify that Echo and Long Running Task didn't trip up asan or valgrind's memory error warnings.

Is it viable to build libflutter_linux_gtk.so from source?

knopp commented 3 years ago

It's a bit more convoluted. NativeShell creates windows that are initially hidden (and shown only after the content is ready). Unfortunately NVIDIA driver seems to have problem with this - creating GLX surface with hidden window sometimes corrupts parent OpenGL context (that causes those crashes and artifacts you're seeing). It happens regardless of GPU, it's definitely a driver thing. I'm currently testing a workaround for this.

knopp commented 3 years ago

I was able to reproduce this with mesa/gallium, which finally allowed me to debug the issue. Looks like this is a bug in Flutter.

knopp commented 3 years ago

Indeed. This is definitely bug in Flutter Rasterizer. When setting resource cache limits it deletes buffer from wrong context. I'll submit PR to fix this tomorrow.

knopp commented 3 years ago

The issue is tracked here: https://github.com/flutter/flutter/issues/84930

nyanpasu64 commented 3 years ago

The issue seems to be resolved after I flutter upgrade to https://github.com/flutter/engine/commit/1eb8a34a3975070c42bc69f3981348dfa4f50a2d.

nyanpasu64 commented 3 years ago

What's the correct procedure to rebuild the necessary parts of nativeshell after upgrading Flutter? Is rm -rf target/{debug,release}/build/nativeshell* and rm -rf target/{debug,release}/incremental/ sufficient? Will it delete more than necessary?

knopp commented 3 years ago

Normally to update depenencies you'd do

$ cargo update
$ dart pub upgrade

then touch any of the dart files in your project (i.e. lib/main.dart) and cargo build should do the right thing. However the corresponding dart and cargo packages have not been published yet. I'll do it in next few days.

I think you shoud also be able modify the cargo.toml and pubspec.yaml to specify git repository (+ the subpath in pubspec.yaml, cargo should find the appropriate subdirectory automatically according to the documentation).

What I normally do during development is that I have the nativeshell repo checked out and use path in both pubspec.yaml and cargo.toml to find the appropriate nativeshell packages.