[bug] [macos] `appWindow.setTheme(null)` then output in input element, app crashes
Opened this issue · 12 comments
Describe the bug
Reproduction case: https://github.com/ayangweb/tauri-input-demo
This bug is so tricky that I've been troubleshooting for ages to figure out the problem
Currently, tested to be a stable reproduction only on macOS, The video is quite long, so please be patient
iShot_2024-10-16_23.41.35.mp4
In my development EcoPaste, I also can stable reproducing bug!
iShot_2024-10-16_23.51.29.mp4
Reproduction
No response
Expected behavior
No response
Full tauri info
output
[✔] Environment
- OS: Mac OS 14.4.0 arm64 (X64)
✔ Xcode Command Line Tools: installed
✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
✔ Rust toolchain: stable-aarch64-apple-darwin (default)
- node: 21.7.1
- pnpm: 9.12.1
- yarn: 1.22.22
- npm: 10.5.0
- bun: 1.1.29
[-] Packages
- tauri 🦀: 2.0.4
- tauri-build 🦀: 2.0.1
- wry 🦀: 0.46.1
- tao 🦀: 0.30.3
- tauri-cli 🦀: 2.0.0-rc.7
- @tauri-apps/api : 2.0.2
- @tauri-apps/cli : 2.0.3
[-] Plugins
- tauri-plugin-dialog 🦀: 2.0.1
- @tauri-apps/plugin-dialog : 2.0.0
- tauri-plugin-process 🦀: 2.0.1
- @tauri-apps/plugin-process : 2.0.0
- tauri-plugin-shell 🦀: 2.0.1
- @tauri-apps/plugin-shell : 2.0.0
- tauri-plugin-autostart 🦀: 2.0.1
- @tauri-apps/plugin-autostart : 2.0.0
- tauri-plugin-fs 🦀: 2.0.1
- @tauri-apps/plugin-fs : 2.0.0
- tauri-plugin-updater 🦀: 2.0.2
- @tauri-apps/plugin-updater : 2.0.0
- tauri-plugin-single-instance 🦀: 2.0.1
- @tauri-apps/plugin-single-instance : not installed!
- tauri-plugin-global-shortcut 🦀: 2.0.1
- @tauri-apps/plugin-global-shortcut : 2.0.0
- tauri-plugin-log 🦀: 2.0.1
- @tauri-apps/plugin-log : 2.0.0
- tauri-plugin-sql 🦀: 2.0.1
- @tauri-apps/plugin-sql : 2.0.0
- tauri-plugin-os 🦀: 2.0.1
- @tauri-apps/plugin-os : 2.0.0
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist
- devUrl: http://localhost:1420/
- framework: React
- bundler: Vite
Stack trace
No response
Additional context
This bug was reported by a user of EcoPaste, so it's not just my computer!
Originally I was trying to achieve this by doing the following, but it was also problematic!
useAsyncEffect(async () => {
const appWindow = getCurrentWebviewWindow();
let isDark = globalStore.appearance.theme === "dark";
if (globalStore.appearance.theme === "auto") {
isDark = (await appWindow.theme()) === "dark"; // Gets the theme color of the window
// or
isDark = window.matchMedia("(prefers-color-scheme: dark)").matches; // It is also the theme color of the window, not the system theme color.
}
appWindow.setTheme(isDark ? "dark" : "light");
globalStore.appearance.isDark = isDark;
}, [globalStore.appearance.theme]);
// If the value of `appWindow.setTheme` is not null or undefined, a change in the system theme will not be triggered.
appWindow.onThemeChanged(async ({ payload }) => {
if (globalStore.appearance.theme !== "auto") return;
globalStore.appearance.isDark = payload === "dark";
});
I don't have a mac device to test on, do you mind trying the theme example in tao
see if it also crashes?
Run this and you should see the instruction in the console
git clone https://github.com/tauri-apps/tao.git
cd tao
cargo run --example theme
Press D for Dark Mode
Press L for Light Mode
Press A for Auto Mode
I can help test, how do I put in an input field element?
Just switching themes won't crash, and neither will the sample repository I sent! Must be entered in the input field
@Legend-Master I don't know how to put a web input box on the page in rust implementation
This is so strange, I thought it's just from switching the theme, I don't quite know how to put an input box in a simple way but maybe you can try the simple example from wry? You will need to manually add in the switch theme code though
https://github.com/tauri-apps/wry/blob/dev/examples/simple.rs
My video has demonstrated it clearly ah, you must enter text in the input box content and then the app will crash right in the auto theme!
Sorry about that, I think I'll leave this to other members who has more knowledge about macos than me
Here is the crash report for the failing thread.
Error happens on [NSCompositeAppearance _flattenedAppearanceNamesList]
, which I believe is used for appearance change on MacOS.
I believe some invalid value has been passed to it and caused the crash.
Time Awake Since Boot: 96 seconds
System Integrity Protection: enabled
Crashed Thread: 0 main Dispatch queue: com.apple.main-thread
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000018f0fb4dc
Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process: exc handler [695]
Application Specific Backtrace 0:
0 CoreFoundation 0x000000018b63eccc __exceptionPreprocess + 176
1 libobjc.A.dylib 0x000000018b126788 objc_exception_throw + 60
2 CoreFoundation 0x000000018b550808 -[__NSPlaceholderArray initWithObjects:count:] + 620
3 CoreFoundation 0x000000018b5ae200 __createArray + 48
4 CoreFoundation 0x000000018b5ae1b4 +[NSArray arrayWithObject:] + 32
5 AppKit 0x000000018ef3b11c -[NSCompositeAppearance _flattenedAppearanceNamesList] + 164
6 AppKit 0x000000018ee29d4c -[NSCompositeAppearance _callCoreUIWithBlock:options:requireBezelTintColor:] + 144
7 AppKit 0x000000018ef31b34 -[NSAppearance _drawInRect:context:options:] + 108
8 AppKit 0x000000018ef38004 -[NSCoreUIImageRep draw] + 276
9 AppKit 0x000000018ef37e94 -[NSImageRep drawInRect:] + 236
10 AppKit 0x000000018ef37b98 -[NSImageRep CGImageForProposedRect:context:hints:] + 480
11 AppKit 0x000000018ef1a6d0 __48-[NSImage CGImageForProposedRect:context:hints:]_block_invoke + 80
12 AppKit 0x000000018ef1a3a4 -[NSImage _usingBestRepresentationForRect:context:hints:body:] + 148
13 AppKit 0x000000018ef19c24 -[NSImage CGImageForProposedRect:context:hints:] + 440
14 AppKit 0x000000018ef3d8a8 -[_NSSimpleImageView updateLayer] + 804
15 AppKit 0x000000018eec8bdc _NSViewUpdateLayer + 84
16 AppKit 0x000000018ee106e4 +[NSAppearance _performWithCurrentAppearance:usingBlock:] + 72
17 AppKit 0x000000018f46ae98 __29-[NSViewBackingLayer display]_block_invoke + 148
18 AppKit 0x000000018ee43394 -[NSFocusStack performWithFocusView:inWindow:usingBlock:] + 96
19 AppKit 0x000000018f46a8f0 -[NSViewBackingLayer display] + 280
20 QuartzCore 0x00000001937d3bd4 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 744
21 QuartzCore 0x0000000193958464 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 512
22 QuartzCore 0x00000001937b6618 _ZN2CA11Transaction6commitEv + 648
23 AppKit 0x000000018ef4866c __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 272
24 AppKit 0x000000018f905e14 ___NSRunLoopObserverCreateWithHandler_block_invoke + 64
25 CoreFoundation 0x000000018b5c9254 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
26 CoreFoundation 0x000000018b5c9140 __CFRunLoopDoObservers + 536
27 CoreFoundation 0x000000018b5c876c __CFRunLoopRun + 776
28 CoreFoundation 0x000000018b5c7e0c CFRunLoopRunSpecific + 608
29 HIToolbox 0x0000000195d63000 RunCurrentEventLoopInMode + 292
30 HIToolbox 0x0000000195d62c90 ReceiveNextEventCommon + 220
31 HIToolbox 0x0000000195d62b94 _BlockUntilNextEventMatchingListInModeWithFilter + 76
32 AppKit 0x000000018ee20970 _DPSNextEvent + 660
33 AppKit 0x000000018f612dec -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700
34 AppKit 0x000000018fad063c -[NSCorrectionPanel _interceptEvents] + 212
35 AppKit 0x000000018fad0f00 -[NSCorrectionPanel showPanelAtRect:inView:primaryString:alternativeStrings:forType:completionHandler:] + 812
36 AppKit 0x000000018f5f0fa4 -[NSSpellChecker showCorrectionIndicatorOfType:primaryString:alternativeStrings:forStringInRect:view:completionHandler:] + 508
37 WebKit 0x00000001af02b9c8 _ZN6WebKit15CorrectionPanel4showEP6NSViewRNS_11WebViewImplEN7WebCore19AlternativeTextTypeERKNS5_9FloatRectERKN3WTF6StringESD_RKNSA_6VectorISB_Lm0ENSA_15CrashOnOverflowELm16ENSA_10FastMallocEEE + 408
38 WebKit 0x00000001af5e2ad4 _ZN6WebKit12WebPageProxy17didReceiveMessageERN3IPC10ConnectionERNS1_7DecoderE + 27340
39 WebKit 0x00000001af6aab6c _ZN3IPC18MessageReceiverMap15dispatchMessageERNS_10ConnectionERNS_7DecoderE + 264
40 WebKit 0x00000001af19c938 _ZN6WebKit15WebProcessProxy17didReceiveMessageERN3IPC10ConnectionERNS1_7DecoderE + 44
41 WebKit 0x00000001af6a5c48 _ZN3IPC10Connection15dispatchMessageENSt3__110unique_ptrINS_7DecoderENS1_14default_deleteIS3_EEEE + 324
42 WebKit 0x00000001af6a60d0 _ZN3IPC10Connection24dispatchIncomingMessagesEv + 556
43 JavaScriptCore 0x00000001a7a73fa0 _ZN3WTF7RunLoop11performWorkEv + 204
44 JavaScriptCore 0x00000001a7a74ec8 _ZN3WTF7RunLoop11performWorkEPv + 36
45 CoreFoundation 0x000000018b5c9eb0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
46 CoreFoundation 0x000000018b5c9e44 __CFRunLoopDoSource0 + 176
47 CoreFoundation 0x000000018b5c9bb4 __CFRunLoopDoSources0 + 244
48 CoreFoundation 0x000000018b5c87a0 __CFRunLoopRun + 828
49 CoreFoundation 0x000000018b5c7e0c CFRunLoopRunSpecific + 608
50 HIToolbox 0x0000000195d63000 RunCurrentEventLoopInMode + 292
51 HIToolbox 0x0000000195d62e3c ReceiveNextEventCommon + 648
52 HIToolbox 0x0000000195d62b94 _BlockUntilNextEventMatchingListInModeWithFilter + 76
53 AppKit 0x000000018ee20970 _DPSNextEvent + 660
54 AppKit 0x000000018f612dec -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700
55 AppKit 0x000000018ee13cb8 -[NSApplication run] + 476
56 tauri-input-demo 0x000000010487e6c4 _ZN3tao13platform_impl8platform10event_loop18EventLoop$LT$T$GT$3run17h9b9a57bad4bcb598E + 680
57 tauri-input-demo 0x00000001048911cc _ZN83_$LT$tauri_runtime_wry..Wry$LT$T$GT$$u20$as$u20$tauri_runtime..Runtime$LT$T$GT$$GT$3run17h3bce137d362304d0E + 368
58 tauri-input-demo 0x0000000104814af8 _ZN5tauri3app16Builder$LT$R$GT$3run17h72ed95462e01ab0eE + 4652
59 tauri-input-demo 0x00000001048c9b04 _ZN20tauri_input_demo_lib3run17hb3013be83cf19578E + 328
60 tauri-input-demo 0x000000010470cdc0 _ZN3std3sys9backtrace28__rust_begin_short_backtrace17h9a9a2b9f9fc557adE + 12
61 tauri-input-demo 0x000000010470cda8 _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17hec51368d477af427E + 16
62 tauri-input-demo 0x0000000104ab2d5c _ZN3std2rt19lang_start_internal17hdd117cb81a316264E + 808
63 tauri-input-demo 0x000000010470ce1c main + 52
64 dyld 0x000000018b1620e0 start + 2360
BTW, this crash was produced on MacOS 14.4.1, other people had this problem on 15.0.1.
But I don't get any crashes with the latest 15.1 MacOS.
I use tauri-plugin-theme and don't have problems with crash!
I made some changes at https://github.com/Legend-Master/tao/tree/fix-set-theme-mac-crash, but I don't have a mac to test it, do you guys have time to test it out? Just try the example first and see if it works, if so clone the tauri
repo and change tauri-runtime-wry
's tao
dependency and pointing it to your local tao
or my branch to see if it still crashes
Cargo.toml
...
[patch.crates-io]
tao = { git = "https://github.com/Legend-Master/tao", branch = "fix-set-theme-mac-crash" }
It didn't crash when I tested it, but I need to test it a few more times
My friend tested it, and it doesn't crash anymore, it's great!🥳