Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] [macos] appWindow.setTheme(null) then output in input element, app crashes #11384

Open
ayangweb opened this issue Oct 16, 2024 · 9 comments
Labels
platform: macOS status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@ayangweb
Copy link

ayangweb commented Oct 16, 2024

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 ☹️ I don't really understand why it's having this 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!

@ayangweb ayangweb added status: needs triage This issue needs to triage, applied to new issues type: bug labels Oct 16, 2024
@ayangweb ayangweb changed the title [bug] appWindow.setTheme(null) then output in input, app crashes [bug] appWindow.setTheme(null) then output in input element, app crashes Oct 16, 2024
@amrbashir amrbashir changed the title [bug] appWindow.setTheme(null) then output in input element, app crashes [bug] [macos] appWindow.setTheme(null) then output in input element, app crashes Oct 17, 2024
@ayangweb
Copy link
Author

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";
});

@Legend-Master
Copy link
Contributor

Legend-Master commented Oct 18, 2024

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

@ayangweb
Copy link
Author

ayangweb commented Oct 18, 2024

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

@Legend-Master
Copy link
Contributor

Legend-Master commented Oct 18, 2024

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

@ayangweb
Copy link
Author

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!

@Legend-Master
Copy link
Contributor

Sorry about that, I think I'll leave this to other members who has more knowledge about macos than me

@ayangweb
Copy link
Author

ayangweb commented Oct 22, 2024

I had five friends try the demo, and it flashed on their computers as well, so I hope this issue can be taken seriously, thanks!🌹

image

@HuakunShen
Copy link

HuakunShen commented Oct 22, 2024

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.

@ayangweb
Copy link
Author

ayangweb commented Oct 22, 2024

I use tauri-plugin-theme and don't have problems with crash!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: macOS status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

4 participants