Repository navigation
fix: stop the macOS app crashing in the background - #4
Merged
Merged
Conversation
Render with Skia instead of Impeller (FLTEnableImpeller=false): Impeller on macOS dereferences a null texture in Canvas::SetupRenderPass when the window's frame size flips (flutter/flutter#185394, fix pending in flutter/flutter#192522). The live clock and the spinners also stop while the app is not in front, so XPath draws no frames of its own in the background, and catch up on resume.
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://fix-macos-background-crash-x-path.abdurahman-i-work.workers.dev (commit c02aabe)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
XPath 1.0.0 (54) crashed on macOS 26.7.1 while it was in the background:
EXC_BAD_ACCESSat0x0onio.flutter.raster, inimpeller::Canvas::SetupRenderPass()(canvas.cc:1615), called fromEmbedderExternalViewEmbedder::SubmitFlutterView.Root cause: a Flutter engine bug
This is flutter/flutter#185394, "[Impeller] Crash on macOS when app is foregrounded" (open, P2, team-macos). The macOS back-buffer cache (
FlutterBackBufferCache) can hand back a surface of the wrong size when the window's frame size changes and then changes back (A → B → A). Examples are a display hot-plug or reconfiguration, a Space or full-screen change, a window drag, or bringing the app to the front. Impeller wraps the mismatchedMTLTexture, the texture invalidates itself, and the render target silently drops it.SetupRenderPassthen dereferences the null texture.Reproduced on our pinned SDK (3.47.6, release build). This used a minimal scratch app, not XPath. A Swift timer shrinks the window by 1 pt and restores it every 2.5 s, which is the driver from #192522. The Flutter side redraws a text once a second, the way
XpClockdoes:FLTEnableImpeller=false)Using the Skia rendering backend (Metal).Changes
macos/Runner/Info.plist:FLTEnableImpeller = false(with a comment linking the issues). I checked the 3.47.6 engine source to confirm macOS still reads this key:FlutterDartProject.enableImpellerreads it, andFlutterEngine runWithEntrypointthen skips--enable-impeller=trueand uses Skia (Metal). XPath uses no Impeller-only features (no fragment shaders, Flutter GPU or backdrop filters). Goldens and widget tests are unaffected becauseflutter testdoes not readInfo.plist.XpClockfollows the app lifecycle using anAppLifecycleListener. It ticks only while the app isresumed. When the app isinactive(visible but not in front),hidden(occluded or minimised) orpaused, the timer stops. On resume, every live duration is rebuilt at once against the current time. The newXpClock.isLive(context)tells widgets whether the app is in front.XpSpinnerstands still while!XpClock.isLive, as it already does under Reduce Motion.Change 1 is the fix. Changes 2 and 3 mean XPath draws no frames of its own while it is not in front (it used to draw one a second for the clock, and 60 fps per spinner). That lowers the crash exposure and saves CPU and battery. On its own it does not fix the engine bug: a display change still causes a frame, and upstream reports idle apps crashing too.
Tests
apps/xp_desktop/test/widgets/xp_clock_test.dartdrives the realflutter/lifecycleplatform channel, the same messages the macOS embedder sends:XpClock ticks every second while the app is in frontXpClock stops while inactive|hidden|paused and catches up on resumeXpClock a still clock stays still in front and awayXpClock starts still when the app is already awayXpClock without a clock above, the system time is liveXpClock spinners stand still while the app is awayTrade-offs and follow-ups