Skip to content

fix: wait for DirectWrite font subsystem before starting at logon#1

Merged
EternityX merged 1 commit into
masterfrom
fix/startup-font-subsystem-wait
Jun 14, 2026
Merged

fix: wait for DirectWrite font subsystem before starting at logon#1
EternityX merged 1 commit into
masterfrom
fix/startup-font-subsystem-wait

Conversation

@EternityX

Copy link
Copy Markdown
Owner

Problem

Starting the app at Windows logon (via the HKCU Run key) could fail with a system-modal "Failed to launch" error box, after which the app never starts. A manual launch always worked.

Root cause

gpui::Application::new() constructs WindowsPlatform::new(), which creates a shared DirectWrite factory (DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED)) and enumerates the system font collection (GetSystemFontCollection). Both depend on the Windows Font Cache Service, which is frequently still starting in the first seconds of a logon session. When they fail, GPUI shows a MB_ICONERROR | MB_SYSTEMMODAL box and then .unwrap() panics, so the process aborts. The existing wait_for_shell() only waits for Shell_TrayWnd, which can appear before the font subsystem is ready.

Fix

Add src/boot.rs with wait_for_font_subsystem(), called right before gpui::Application::new(). It probes the same DirectWrite calls with backoff (120 × 250 ms ≈ 30 s) until they succeed, and logs late readiness / timeout to %APPDATA%\Polterdesk\startup.log. On a warm machine the probe succeeds on the first attempt, so there is no added startup latency. The tray thread is spawned before the wait so the tray icon still appears promptly at boot.

Tests

tests/boot_test.rs covers the retry harness (poll_until_ready) deterministically with an injected probe.

Verification

  • cargo clippy -- -D warnings — clean
  • cargo build --release — builds
  • cargo test --test boot_test — 4 passed

The boot-time fix itself is best confirmed with a reboot (autostart enabled).

When launched at logon via the HKCU Run key, the app could fail with a
system-modal "Failed to launch" error box and never start, while a manual
launch always worked.

gpui::Application::new() constructs WindowsPlatform::new(), which creates a
shared DirectWrite factory (DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED))
and enumerates the system font collection (GetSystemFontCollection). Both
depend on the Windows Font Cache Service, which is often still starting in the
first seconds of a session, so those calls fail and GPUI panics after showing
the error box. Waiting for Shell_TrayWnd is not sufficient because it can
appear before the font subsystem is ready.

Add boot::wait_for_font_subsystem(), called right before
gpui::Application::new(), which probes the same DirectWrite calls with backoff
(~30s) until they succeed and logs late readiness/failures to
%APPDATA%\Polterdesk\startup.log. On a warm machine the probe succeeds on the
first attempt, so there is no added startup latency. The tray thread is spawned
before the wait so the tray icon still appears promptly at boot.
@EternityX EternityX merged commit 1cec6ef into master Jun 14, 2026
3 checks passed
@EternityX EternityX deleted the fix/startup-font-subsystem-wait branch June 14, 2026 12:13
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.

1 participant