tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.38k stars 2.58k forks source link

[bug] Tauri2 crashes immediately on Windows 10 LTSC 2016 #11674

Open Jnschrber opened 1 week ago

Jnschrber commented 1 week ago

Describe the bug

Tauri2 is not starting on Windows 10 LTSC 2016. When executing the .exe it immediately terminates without any error message. When checking the Windows 10 EventLogs, the following Application Error is shown:

Faulting application name: tauri-app.exe, version: 0.1.0.0, time stamp: 0x6732271b
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc0000005
Fault offset: 0x00000000
Faulting process id: 0x26ec
Faulting application start time: 0x01db344f7438982b
Faulting application path: C:\Users\Administrator\Desktop\TAURI\tauri-app.exe
Faulting module path: unknown
Report Id: cded0ad4-2365-481b-9e34-2c7c50b6831b
Faulting package full name: 
Faulting package-relative application ID: 

https://github.com/user-attachments/assets/1e5f7f1c-7c16-49c5-8612-e26f92f99353

Reproduction

Create a new sample Project with:

cargo install create-tauri-app --locked cargo create-tauri-app

Build the Project:

cargo build

Expected behavior

Tauri should start and open the sample GUI.

Full tauri info output

[✔] Environment                                                                                
    - OS: Windows 10.0.19045 x86_64 (X64)                                                      
    ✔ WebView2: 130.0.2849.80                                                                  
    ✔ MSVC:                                                                                    
        - Visual Studio Build Tools 2022                                                       
        - Visual Studio Professional 2022                                                      
    ✔ rustc: 1.82.0 (f6e511eec 2024-10-15)                                                     
    ✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)                                                     
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)                                                    
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN) 
    - node: 20.15.0                                                                            
    - npm: 10.7.0                                                                              

[-] Packages                                                                                   
    - tauri 🦀: 2.1.1                                                                           
    - tauri-build 🦀: 2.0.3                                                                     
    - wry 🦀: 0.47.0                                                                            
    - tao 🦀: 0.30.7                                                                            
    - tauri-cli 🦀: 2.0.0-rc.16                                                                 

[-] Plugins                                                                                    
    - tauri-plugin-shell 🦀: 2.0.2                                                              

[-] App                                                                                        
    - build-type: bundle                                                                       
    - CSP: unset                                                                               
    - frontendDist: ../src

Stack trace

No response

Additional context

The exact same application is working fine on:

FabianLars commented 1 week ago

Can you try starting it from inside a terminal session (shift + right-click on the folder -> Open powershell -> .\tauri-app.exe).

This way you won't lose the error message if there's any.

In theory it should still be supported by webview2 and rust.

Jnschrber commented 1 week ago

I had already done that. However, there is no error message here either. Version of installed WebView2: 130.0.2849.80

image

FabianLars commented 1 week ago

hmm, that's unfortunate. What about a debug build via tauri build --debug ? Should behave like the release build but keeping the console attached. I doubt it's any better but still worth a try imo

Jnschrber commented 1 week ago

As I build Tauri with Cargo, the standard build is a debug version. Nevertheless, I have just built a release version with cargo build --release. Now I have both builds. When executing the release version, no ApplicationError is written to the Windows 10 EventLogs. When executing the debug version, the error is written to the EventLogs as described in the description.

Michto8 commented 2 days ago

Hello, I had a similar problem since switching to version 2 of tauri:. My application compiled by tauri build --target i686-pc-windows-msvc crashed at startup on my Windows 2016 workstations with the same message: "Application Error..." After doing a fork of tauri and tao i put in comment this line: (tao\src\platform_impl\windows\event_loop.rs) super::dark_mode::allow_dark_mode_for_app(true); My application doesnt crash anymore. I hope this can help someone.

amrbashir commented 2 days ago

@Michto8 thanks for tracking this down, since you have a Windows 10 system (and it would take me a while to setup one), could you try to pin it down to an exact line in tao\src\platform_impl\windows\dark_mode.rs ?

Michto8 commented 1 day ago

I will try on windows 2016 and windows 2010.

First on windows 2016:

WIN10_BUILD_VERSION return me 14393. The program call ALLOW_DARK_MODE_FOR_APP and the application hang.

But if i return None in this function i dont have any error ` static ALLOW_DARK_MODE_FOR_APP: Lazy<Option> = Lazy::new(|| unsafe {

println!("NO lambda ALLOW_DARK_MODE_FOR_APP"); return None;

if HMODULE(*HUXTHEME as _).is_invalid() { return None; }

GetProcAddress( HMODULE(HUXTHEME as _), PCSTR::from_raw(UXTHEME_ALLOWDARKMODEFORAPP_ORDINAL as usize as mut _), ) .map(|handle| std::mem::transmute(handle)) }); ` Im running my program on 32 bits so uxtheme.dll are loaded from c:\Windows\Syswow64. The ordinal number for UXTHEME_ALLOWDARKMODEFORAPP_ORDINAL are 135. If i inspect functions in this dll with dependency walker this dont seem to match with the function to call.

https://stackoverflow.com/questions/53501268/win10-dark-theme-how-to-use-in-winapi

https://learn.microsoft.com/en-us/cpp/build/getprocaddress?view=msvc-170

Because you are calling the DLL function through a pointer and there is no compile-time type checking, make sure that the parameters to the function are correct so that you do not overstep the memory allocated on the stack and cause an access violation.

Jnschrber commented 1 day ago

Hi, I have also just managed to create a working Tauri2 App with this hint.

Hello, I had a similar problem since switching to version 2 of tauri:. My application compiled by tauri build --target i686-pc-windows-msvc crashed at startup on my Windows 2016 workstations with the same message: "Application Error..." After doing a fork of tauri and tao i put in comment this line: (tao\src\platform_impl\windows\event_loop.rs) super::dark_mode::allow_dark_mode_for_app(true); My application doesnt crash anymore. I hope this can help someone.

What I have figured out so far is the following: The line responsible for the app to crash on startup in tao\src\platform_impl\windows\dark_mode.rs is line 84. See: https://github.com/tauri-apps/tao/blob/fa9aaa6066dcc0316d57038fc1b1e3353dc5c3e7/src/platform_impl/windows/dark_mode.rs#L84C1-L84C59

unsafe { _allow_dark_mode_for_app(is_dark_mode) };

When I disable execution of this particular line, the app starts normally and as far as I can tell works properly.

What I also found out is that there is an attribute DARK_MODE_SUPPORTED in the file, which indicates that Windows versions lower than 17763 are not supporting dark mode. However, this attribute is not taken into account in the allow_dark_mode_for_app() function.

static DARK_MODE_SUPPORTED: Lazy<bool> = Lazy::new(|| {
  // We won't try to do anything for windows versions < 17763
  // (Windows 10 October 2018 update)
  match *WIN10_BUILD_VERSION {
    Some(v) => v >= 17763,
    None => false,
  }
});

If the WIN10_BUILD_VERSION is smaller than 18362 it executes the line 84 regardless wether DARK_MODE_SUPPORTED is true or false. Therefore I added another condition to check wether the DARK_MODE_SUPPORTED is true to only execute line 84 in that case. (see below)

if let Some(ver) = *WIN10_BUILD_VERSION {
    if ver < 18362 {
      if let Some(_allow_dark_mode_for_app) = *ALLOW_DARK_MODE_FOR_APP {
        unsafe { _allow_dark_mode_for_app(is_dark_mode) };
      }
    } else if let Some(_set_preferred_app_mode) = *SET_PREFERRED_APP_MODE {
      let mode = if is_dark_mode {
        PreferredAppMode::AllowDark
      } else {
        PreferredAppMode::Default
      };
      unsafe { _set_preferred_app_mode(mode) };
    }
  }

changed to:

if let Some(ver) = *WIN10_BUILD_VERSION {
    // in case Windows 10 Build version < 18362, we have to call a special command (_allow_dark_mode_for_app)
    if ver < 18362 {
        // but only call that command if the dark mode is supported...
        if *DARK_MODE_SUPPORTED {
            if let Some(_allow_dark_mode_for_app) = *ALLOW_DARK_MODE_FOR_APP {
                unsafe { _allow_dark_mode_for_app(is_dark_mode) };
            }
        }
    } else if let Some(_set_preferred_app_mode) = *SET_PREFERRED_APP_MODE {
      let mode = if is_dark_mode {
        PreferredAppMode::AllowDark
      } else {
        PreferredAppMode::Default
      };
      unsafe { _set_preferred_app_mode(mode) };
    }
  }

Would be great if someone with more background knowledge could check that fix suggested, and then create a pull request for the tao repository.