Skip to content

fix: disable WebKit DMABuf renderer on Linux#148

Merged
zouyonghe merged 3 commits into
AstrBotDevs:mainfrom
zouyonghe:fix/linux-webkit-dmabuf-workaround
Jul 3, 2026
Merged

fix: disable WebKit DMABuf renderer on Linux#148
zouyonghe merged 3 commits into
AstrBotDevs:mainfrom
zouyonghe:fix/linux-webkit-dmabuf-workaround

Conversation

@zouyonghe

@zouyonghe zouyonghe commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #147.

On Linux Wayland sessions, set WEBKIT_DISABLE_DMABUF_RENDERER=1 before Tauri creates the WebKitGTK webview. This works around a known WebKitGTK/Tauri upstream issue where Wayland + NVIDIA environments can fail to start or render with:

Gdk-Message: Error 71 (Protocol error) dispatching to Wayland display.

The variable is only set when:

  • WAYLAND_DISPLAY is present, so X11 Linux sessions are left unchanged.
  • WEBKIT_DISABLE_DMABUF_RENDERER is not already provided, so manual overrides such as WEBKIT_DISABLE_DMABUF_RENDERER=0 remain possible.

Context

The reported Fedora KDE/Wayland/NVIDIA crash matches upstream reports:

WebKitGTK itself reads WEBKIT_DISABLE_DMABUF_RENDERER in AcceleratedBackingStore.cpp, so this is an application-level startup workaround for an upstream rendering path rather than an AstrBot backend/WebUI change.

Changes

  • Add a Linux-only startup workaround before tauri::Builder::default().
  • Scope the default workaround to Wayland sessions via WAYLAND_DISPLAY.
  • Preserve existing user-provided WEBKIT_DISABLE_DMABUF_RENDERER values.
  • Add a small unit test for the Wayland + override behavior.

Verification

  • rtk cargo fmt --all --check
  • rtk cargo test app_runtime::tests::webkit_dmabuf_workaround_is_set_only_for_wayland_without_override
  • rtk cargo test

Note: one full cargo test run initially hit an existing-looking concurrent-state failure in desktop_settings::tests::write_desktop_setting_preserves_unknown_fields; that specific test passed when rerun alone, and the full suite passed on the next run.

Notes

Disabling WebKitGTK's DMABuf renderer can reduce rendering performance on some Linux systems, so the workaround is limited to Wayland sessions and still allows users to override the variable explicitly.

Summary by Sourcery

Apply a Linux-only startup workaround that configures WebKitGTK to avoid DMABuf rendering issues on Wayland sessions.

Bug Fixes:

  • Disable WebKitGTK's DMABuf renderer by default on Linux Wayland sessions to prevent startup/rendering failures, while preserving user overrides of the related environment variable.

Tests:

  • Add a unit test verifying that the WebKit DMABuf workaround is only applied when running under Wayland and no explicit override is set.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a workaround for Linux WebKit DMABUF renderer issues by setting the WEBKIT_DISABLE_DMABUF_RENDERER environment variable to 1 if it is not already set. This is executed at the start of the application run process on Linux. Unit tests are also added to verify this behavior. Feedback suggests wrapping the std::env::set_var call in an unsafe block to comply with Rust 1.81.0+ and Rust 2024 edition requirements, as modifying environment variables can cause data races in multi-threaded environments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

if should_set_webkit_dmabuf_renderer_env(
std::env::var_os(WEBKIT_DISABLE_DMABUF_RENDERER_ENV).as_deref(),
) {
std::env::set_var(WEBKIT_DISABLE_DMABUF_RENDERER_ENV, "1");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Starting in Rust 1.81.0 (and enforced in the Rust 2024 edition), std::env::set_var is marked as unsafe because modifying environment variables in a multi-threaded environment can lead to data races and undefined behavior.

To ensure compatibility with newer Rust editions and prevent compilation errors or deprecation warnings, wrap the call in an unsafe block. Since this function is called at the very beginning of main before any other threads are spawned, it is safe to do so.

        // SAFETY: This is called at the very beginning of the application's execution
        // before any other threads are spawned, ensuring no data races occur.
        unsafe {
            std::env::set_var(WEBKIT_DISABLE_DMABUF_RENDERER_ENV, "1");
        }

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/app_runtime.rs" line_range="22-31" />
<code_context>
+    existing_value.is_none() && wayland_display.is_some()
+}
+
+#[cfg(target_os = "linux")]
+fn configure_linux_webkit_workarounds() {
+    if should_set_webkit_dmabuf_renderer_env(
</code_context>
<issue_to_address>
**suggestion:** Consider surfacing when the workaround is applied to aid troubleshooting

Because this env var can materially change rendering on Linux, it would help troubleshooting if we logged when the workaround is applied (e.g., right after or inside `configure_linux_webkit_workarounds`). That way, differences in WebKit/Wayland behavior tied to this flag are easier to diagnose.

Suggested implementation:

```rust
#[cfg(target_os = "linux")]
fn configure_linux_webkit_workarounds() {
    if should_set_webkit_dmabuf_renderer_env(
        std::env::var_os(WEBKIT_DISABLE_DMABUF_RENDERER_ENV).as_deref(),
        std::env::var_os(WAYLAND_DISPLAY_ENV).as_deref(),
    ) {
        std::env::set_var(WEBKIT_DISABLE_DMABUF_RENDERER_ENV, "1");
        tracing::info!(
            "Applied Linux WebKit workaround: set {}=1 (Wayland display detected, no existing value)",
            WEBKIT_DISABLE_DMABUF_RENDERER_ENV
        );
    }
}

```

1. Ensure that `tracing` (or your chosen logging crate) is available and initialized in the application startup path so that this log line is emitted (e.g., via `tracing_subscriber`).
2. If the project uses a different logging macro (such as `log::info!` or a custom logger), replace `tracing::info!` with the appropriate macro to match the existing logging conventions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src-tauri/src/app_runtime.rs
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe zouyonghe merged commit 400050f into AstrBotDevs:main Jul 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Wayland + KDE Plasma + Nvidia闭源驱动下会出现UI无法正常渲染

1 participant