tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
82.68k stars 2.48k forks source link

[bug] Cannot run WebGL renders in the Tauri desktop app. WebGL: Context lost #6559

Open AsgrimS opened 1 year ago

AsgrimS commented 1 year ago

Describe the bug

When I try to implement three.js scenes into my tuari app it doesn't work at all in the app window, but it works when I open the app in the browser directly.

My console of the desktop app is spammed with WebGL: context lost and my CPU usage skyrockets image

Reproduction

  1. Clone https://github.com/AsgrimS/dice-nexus -> https://github.com/AsgrimS/tauri-webgl
  2. pnpm install
  3. pnpm tauri dev

Expected behavior

Working WebGL render in both browser and desktop app

image

Platform and versions

Environment
  › OS: Arch Linux Unknown X64
  › Node.js: 18.12.1
  › npm: 8.19.2
  › pnpm: 7.30.3
  › yarn: 3.3.1
  › rustup: 1.25.2
  › rustc: 1.67.1
  › cargo: 1.67.1
  › Rust toolchain: stable-x86_64-unknown-linux-gnu

Stack trace

No response

Additional context

No response

FabianLars commented 1 year ago

Could you also try it in the epiphany browser (also known as "gnome web")? Just to double check if it's tauri specific or webkitgtk as a whole.

AsgrimS commented 1 year ago

Could you also try it in the epiphany browser (also known as "gnome web")? Just to double check if it's tauri specific or webkitgtk as a whole.

Hi, thanks for the fast reply.

I opened it in epiphany and the issue is the same as in the desktop app, so it's probably an issue with webkitgtk. ( The previous attempt that worked was in Brave browser )

FabianLars commented 1 year ago

Damn, that's unfortunate. They just introduced webgl2 support in webkitgtk 2.40 so it either broke something or their webgl2 implementation isn't quite compatible with threejs or something? 🤔 I'm gonna play around with your reproduction repo after the weekend when i have access to my Linux machine again!

AsgrimS commented 1 year ago

I checked and I had webkit2gtk=2.40.0-2 installed. I've downgraded it to webkit2gtk=2.38.5-1 and render inside the tauri desktop app window started to work. image

I think this pretty much confirms the fact that the update for webkitgtk broke things. In the epiphany it still doesn't work but it's probably bundled with the new webkitgtk or sth.

ImUrX commented 1 year ago

a user having this issue also told me WEBKIT_DISABLE_COMPOSITING_MODE=1 helps

keremnymn commented 1 year ago

Same issue here, I can't use MapLibre GL JS on Tauri. Any suggestions? Should I also downgrade the webkit2gtk version?

qqkkwan commented 10 months ago

I checked and I had webkit2gtk=2.40.0-2 installed. I've downgraded it to webkit2gtk=2.38.5-1 and render inside the tauri desktop app window started to work. image

I think this pretty much confirms the fact that the update for webkitgtk broke things. In the epiphany it still doesn't work but it's probably bundled with the new webkitgtk or sth.

how to downgrade to webkit2gtk=2.38.5-1 ?

ferserc1 commented 10 months ago

In my case the canvas does not even return a render context. It returns null with both WebGL and 2D.

I have reinstalled Ubuntu 22.04 from scratch and only configured the bare minimum needed to run my application, so I have a pretty clean install. With this configuration I have libwebkit2gtk installed like this:

$ dpkg -l | grep webkit2gtk
ii  libwebkit2gtk-4.0-37:amd64                 2.42.2-0ubuntu0.22.04.1                               amd64        Web content engine library for GTK
ii  libwebkit2gtk-4.0-dev:amd64                2.42.2-0ubuntu0.22.04.1                               amd64        Web content engine library for GTK - development files

How can I downgrade to webkit2gtk=2.38.5-1?

keremnymn commented 10 months ago

@ferserc1 I overcame this issue by installing Ubuntu Mantic release.

Links2004 commented 9 months ago

same problem happens on Arch/EndeavourOS too, but no way to downgrade to 2.38.5-1 (to much to downgrade in a rolling release OS)

[⚠] Environment
    - OS: EndeavourOS Rolling Release X64
    ✔ webkit2gtk-4.1: 2.42.3
    ✔ rsvg2: 2.57.0
    ✔ rustc: 1.74.1 (a28077b28 2023-12-04) (Arch Linux rust 1:1.74.1-1)
    ✔ cargo: 1.74.1

image

caprilesport commented 8 months ago

Im also having the exact same issue as @Links2004.

What is curious is that in my desktop computer, which runs endeavourOS im having the issue (nvidia graphics card and no integrated GPU), but on my notebook running Ubuntu, also using the libwebkit2gtk version 2.42.4, it works flawlessly. Makes me wonder if it isn't related to the NVIDIA GPU in some way.

ImUrX commented 8 months ago

Btw this only happens in nvidia x11 desktop environments

atinylittleshell commented 7 months ago

What can we do as app developer to ensure end users can use our tauri app with webgl? This feels like a critical limitation of tauri delegating webview to the OS..