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] "Command failed with exit code 3221225781" and "Command failed with exit code 4294967295"? #6924

Closed
SafeShows opened this issue May 9, 2023 · 15 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@SafeShows
Copy link

Describe the bug

image

Reproduction

No response

Expected behavior

The app should start and print sim connect data

Platform and versions

[✔] Environment
    - OS: Windows 10.0.22621 X64
    ✔ WebView2: 113.0.1774.35
    ✔ MSVC:
        - Visual Studio Community 2022
        - Visual Studio Build Tools 2022
    ✔ rustc: 1.69.0 (84c898d65 2023-04-16)
    ✔ Cargo: 1.69.0 (6e9a83356 2023-04-12)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 18.15.0
    - pnpm: 8.4.0
    - yarn: 1.22.19
    - npm: 9.5.0

[-] Packages
    - tauri [RUST]: 1.3.0
    - tauri-build [RUST]: 1.3.0
    - wry [RUST]: 0.24.3
    - tao [RUST]: 0.16.1
    - @tauri-apps/api [NPM]: 1.3.0
    - @tauri-apps/cli [NPM]: 1.3.0 (outdated, latest: 1.3.1)

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace

No response

Additional context

main.rs

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use sim_connect::SimConnect;

mod events;
mod sim_connect;

fn main() {
    let _sim = SimConnect::new();
    tauri::Builder::default()
        .setup(|app| {
            let _app_handle = app.handle();
            Ok(())
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

events.rs

use simconnect_sdk::SimConnectObject;

#[derive(Debug, Clone, SimConnectObject)]
#[simconnect(period = "second")]
#[allow(dead_code)]
pub struct AircraftData {
    #[simconnect(name = "TITLE")]
    aircraft_title: String,
    #[simconnect(name = "CATEGORY")]
    aircraft_category: String,
    #[simconnect(name = "PLANE LATITUDE", unit = "degrees")]
    aircraft_lat: f64,
    #[simconnect(name = "PLANE LONGITUDE", unit = "degrees")]
    aircraft_lon: f64,
    #[simconnect(name = "PLANE ALTITUDE", unit = "feet")]
    aircraft_alt: f64,
    #[simconnect(name = "PLANE ALT ABOVE GROUND", unit = "feet")]
    aircraft_alt_above_ground: f64,
    #[simconnect(name = "VERTICAL SPEED", unit = "ft/min")]
    aircraft_vertical_speed: f64,
}

#[derive(Debug, Clone, SimConnectObject)]
#[simconnect(period = "second")]
#[allow(dead_code)]
pub struct SimData {
    #[simconnect(name = "SIM ON GROUND")]
    sim_on_ground: bool,
}

#[derive(Debug)]
#[allow(dead_code)]
pub enum SimConnectEvent {
    AircraftData(AircraftData),
    SimData(SimData),
}

#[allow(dead_code)]
pub enum TauriEvent {}

sim_connect.rs

use std::{thread, time::Duration};

use crate::events::{AircraftData, SimData};
use simconnect_sdk::SimConnect as Sim;

pub struct SimConnect {}

impl SimConnect {
    pub fn new() -> Self {
        thread::spawn(|| {
            let client = Sim::new("VirtualFlyer");
            match client {
                Ok(mut c) => loop {
                    {
                        match c.get_next_dispatch() {
                            Ok(notification) => match notification {
                                Some(event) => match event {
                                    simconnect_sdk::Notification::Open => {
                                        println!("SIM CONNECTED");
                                        c.register_object::<SimData>().ok();
                                        c.register_object::<AircraftData>().ok();
                                    }
                                    simconnect_sdk::Notification::Object(obj) => {
                                        if let Ok(sim_data) = SimData::try_from(&obj) {
                                            println!("{:?}", sim_data);
                                        }
                                        if let Ok(sim_data) = AircraftData::try_from(&obj) {
                                            println!("{:?}", sim_data);
                                        }
                                    }
                                    _ => {}
                                },
                                None => {}
                            },
                            Err(_) => {}
                        }
                    }
                    thread::sleep(Duration::from_millis(20));
                },
                Err(_) => {}
            }
        });
        Self {}
    }
}

cargo.toml

[package]
name = "virtual_flyer"
version = "0.0.0"
description = "A Tauri App"
authors = ["SafeShows#5341 <[email protected]>"]
license = ""
repository = ""
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "1.3", features = [] }

[dependencies]
simconnect-sdk = { version = "0.2.2", features = ["derive"] }

tauri = { version = "1.3", features = ["shell-open", "window-close", "window-hide", "window-maximize", "window-minimize", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.28.0", features = ["full"] }
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
[features]
custom-protocol = ["tauri/custom-protocol"]

More context can be gotten from discord -> https://discord.com/channels/616186924390023171/1105525711453827152

@SafeShows SafeShows added status: needs triage This issue needs to triage, applied to new issues type: bug labels May 9, 2023
@SafeShows SafeShows changed the title [bug] [bug] Why am I getting "Command failed with exit code 3221225781" and "Command failed with exit code 4294967295"? May 9, 2023
@SafeShows SafeShows changed the title [bug] Why am I getting "Command failed with exit code 3221225781" and "Command failed with exit code 4294967295"? [bug] "Command failed with exit code 3221225781" and "Command failed with exit code 4294967295"? May 9, 2023
@SafeShows
Copy link
Author

Could maybe the simconnect_sdk developer help out? @mihai-dinculescu

@mihai-dinculescu
Copy link

I'll have a look 👍

@SafeShows
Copy link
Author

SafeShows commented May 9, 2023

I'll have a look 👍

I have done my research and have gotten and figured out that it's something with the NonNull<c_type> in base.rs of simconnect_sdk

@SafeShows
Copy link
Author

as in it doesn't implement Send
@mihai-dinculescu

@mihai-dinculescu
Copy link

mihai-dinculescu commented May 9, 2023

That shouldn't be a problem because nothing from SimConnect is sent between threads in your case. Also, I would expect the compiler to complain if that is true.

Please try and download the MSFS SDK and place MSFS SDK\SimConnect SDK\lib\Simconnect.dll in src_tauri.

@mihai-dinculescu
Copy link

By the way, I do have a working example of simconnect-sdk + tauri if you're looking for inspiration.

@SafeShows
Copy link
Author

SafeShows commented May 9, 2023

That shouldn't be a problem because nothing from SimConnect is sent between threads in your case. Also, I would expect the compiler to complain if that is true.

well tauri uses tokio and if I switch to tokio::spawn(async {}) then it gives me issues

@amrbashir
Copy link
Member

@SafeShows
Copy link
Author

you could use https://docs.rs/tauri/latest/tauri/async_runtime/fn.spawn.html

That gives me this

   Compiling virtual_flyer v0.0.0 (A:\Programming\Projects\VirtualFlyer\src-tauri)
error: future cannot be sent between threads safely
   --> src\sim_connect.rs:10:37
    |
10  |           tauri::async_runtime::spawn(async {
    |  _____________________________________^
11  | |             let client = Sim::new("VirtualFlyer");
12  | |             match client {
13  | |                 Ok(mut c) => loop {
...   |
39  | |             };
40  | |         });
    | |_________^ future created by async block is not `Send`
    |
    = help: within `[async block@src\sim_connect.rs:10:37: 40:10]`, the trait `Send` is not implemented for `NonNull<c_void>`
note: future is not `Send` as this value is used across an await
   --> src\sim_connect.rs:36:66
    |
13  |                 Ok(mut c) => loop {
    |                    ----- has type `simconnect_sdk::SimConnect` which is not `Send`
...
36  |                     tokio::time::sleep(Duration::from_millis(20)).await;
    |                                                                  ^^^^^^ await occurs here, with `mut c` maybe used later
37  |                 },
    |                 - `mut c` is later dropped here
note: required by a bound in `tauri::async_runtime::spawn`
   --> C:\Users\the_b\.cargo\registry\src\github.aaakk.us.kg-1ecc6299db9ec823\tauri-1.3.0\src\async_runtime.rs:270:15
    |
270 |   F: Future + Send + 'static,
    |               ^^^^ required by this bound in `spawn`

error: could not compile `virtual_flyer` due to previous error

@SafeShows
Copy link
Author

and this is the reason why I brought you in @mihai-dinculescu as it has to do with your thing

Not trying to sound offensive sorry if I did

@amrbashir
Copy link
Member

amrbashir commented May 10, 2023

that function is the same as tokio::spawn so it is NOT an issue in our API or in tokio, you have a type SimConnect which is not Send, and if the library author specified this type as not Send then they must have a reason to do so.

Your only options are 1) Wrap this type in a Send type or 2) create this type inside a thread or inside the async closure and communicate with it using channels or something similar.

This looks more like a "help me with rust" issue and not something specific to our API so I would suggest asking in our discord for help or in the rust discord server.

@amrbashir amrbashir closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2023
@FabianLars
Copy link
Member

This looks more like a "help me with rust" issue and not something specific to our API so I would suggest asking in our discord for help or in the rust discord server.

This is where we started. I asked them to open an issue so we can loop in you, Lucas, and more importantly the simconnect maintainers if needed. Since the discussion here derailed a bit from the actual issue we were facing on discord i'll explain again what we're actually facing, and ignore the Send stuff for this:

The issue we've had was that once you added Sim::new() anywhere in the tauri app, even in a command that's never invoked tauri dev will stop working, as-in not even the main function will run, while cargo run keeps working fine (at least for me, OP got a WebView2 panic with cargo run, but i think that's another issue).

And for this issue it didn't matter if i used a std thread, tokio task (via tokio or tokio::async_runtime) or straight up used the main thread.

The only issue i found on the internet with the same error code was about vc redist so i made sure i have various versions installed and prevented Tauri from statically linking the runtime STATIC_VCRUNTIME="false" - didn't help. Completely removing tauri-build didn't make a difference either.

@FabianLars
Copy link
Member

Please try and download the MSFS SDK and place MSFS SDK\SimConnect SDK\lib\Simconnect.dll in src_tauri.

Thanks for helping out btw :) And that indeed worked for me! Though i still don't get why cargo run worked without it tbh. Maybe it's because tauri dev calls cargo build and executes that produced binary manually, but there's still something i'm missing here to make it make sense to me 🤔

@mihai-dinculescu
Copy link

@FabianLars, that is a very good description of the behavior.
simconnect-sdk's build.rs normally links the DLL, and that works fine in typical cases like cargo run. However, something in Tauri breaks that. I'm still trying to figure out what and why, but it's on my TODO list to investigate at some point.

Btw, Tauri release builds also require the DLL to be specified as a resource.

@SafeShows
Copy link
Author

Btw, Tauri release builds also require the DLL to be specified as a resource.

Okay thx adding the dll to the resources of tauri.conf.json fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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