#Tauri just crashes without any error at all (backend)

11 messages · Page 1 of 1 (latest)

eternal solar
#

Hello everyone! I'm using Tauri for the first time (been a long term developer of Electron) and it seems to be promising to me. But I'm facing the issue of the stability of Tauri, where it just simply crashes without any error output from the log:

...
Screenshot saved to ../screenshot.bmp!
Capturing screen: 1728x1117
Expected frame size: 7720704
Screenshotting...
Creating an ImageBuffer...
Screenshot saved to ../screenshot.bmp!
Capturing screen: 1728x1117
Expected frame size: 7720704
Screenshotting...
Creating an ImageBuffer...
Screenshot saved to ../screenshot.bmp!
✨  Done in 100.97s.

This occur after some time of taking screenshots. I've tried many other variants such as increasing timeout (I'm aware that the window is not appearing, this is expected)

tauri info

[✔] Environment
    - OS: Mac OS 15.2.0 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.84.0 (9fc6b4312 2025-01-07)
    ✔ cargo: 1.84.0 (66221abde 2024-11-19)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 18.18.1
    - yarn: 1.22.21
    - npm: 9.8.1

[-] Packages
    - tauri 🦀: 2.2.1
    - tauri-build 🦀: 2.0.5
    - wry 🦀: 0.48.0
    - tao 🦀: 0.31.1
    - @tauri-apps/api : 2.2.0
    - @tauri-apps/cli : 2.2.3

[-] Plugins
    - tauri-plugin-opener 🦀: 2.2.3
    - @tauri-apps/plugin-opener : 2.2.3

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

Reproductive Code:

src-tauri/main.rs

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

mod core; // Include the `core` module

fn main() {
    core::preview_screen::capture_interval("../screenshot.bmp", Some(200), 50).unwrap_or_else(|err| {
        println!("Failed to capture screenshot: {}", err);
    });

    syva_lib::run();
}

src-tauri/core/mod.rs

pub mod preview_screen;
#

src/core/preview_screen.rs

use scrap::{Capturer, Display};
use std::{fs::File, io::BufWriter, thread, time::{Duration, Instant}};
use image::{imageops::resize, ImageBuffer, Rgba, ImageFormat};
pub fn capture(
    file_name: &str,
    quality: u8,
) -> Result<(), Box<dyn std::error::Error>> {
    let display = Display::primary().expect("Failed to get primary display");
    let mut capturer = Capturer::new(display).expect("Failed to start capture");
    let (width, height) = (capturer.width(), capturer.height());
    let expected_size = width * height * 4;
    println!("Capturing screen: {}x{}", width, height);
    println!("Screenshotting...");
    let frame = loop {
        match capturer.frame() {
            Ok(frame) => {
                break frame.to_vec();
            }
            Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {
                thread::sleep(Duration::from_millis(10));
            }
            Err(e) => {
                return Err(Box::new(e));
            }
        }
    };
    println!("Creating an ImageBuffer...");
    let buffer: ImageBuffer<Rgba<u8>, Vec<u8>> =
        ImageBuffer::from_raw(width as u32, height as u32, frame)
            .expect("Failed to create ImageBuffer");
    buffer.save_with_format(file_name, ImageFormat::Bmp)?;
    println!("Screenshot saved to {}!", file_name);
    Ok(())
}

pub fn capture_interval(
    file_name: &str,
    interval: Option<u64>,
    quality: u8,
) -> Result<(), Box<dyn std::error::Error>> {
    let interval = interval.unwrap_or(1000); 
    loop {
        let start = Instant::now();

        if let Err(e) = capture(file_name, quality) {
            println!("Error during capture: {}", e);
        }

        let elapsed = start.elapsed();
        if elapsed < Duration::from_millis(interval) {
            thread::sleep(Duration::from_millis(interval) - elapsed);
        } else {
            println!("Capture took longer than the interval: {:?}", elapsed);
        }
    }
}
#

Cargo.toml

[package]
name = "syva"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"

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

[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "syva_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

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

[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
scrap = "0.5"
image = "0.25"
rayon = "1.5"
tokio = { version = "1.0", features = ["full"] }
log = "0.4"
env_logger = "0.9"
empty talon
#

From the code you showed i'm failing to see the connection to tauri here.
Does it have the same issue if you remove the syva_lib::run(); line and/or run the app via cargo run instead of tauri dev?

eternal solar
#

I found the issue, its because Capturer::new(...) from scrap should only initialized once. So it has nothing to do with Tauri.

However, do you have recommendation for me how I can debug this easier since I didnt received any error at all?

empty talon
#

Not really, no. This sounds like an issue with the library

#

Not seeing an error i mean

#

if it's something in the ffi bridge failing (i assume they use some kind of ffi) they should try to expose that somehow to the library consumer

#

if something fails silently it's hard or close to impossible to debug directly. In those cases i just spam println!() / dbg!() lines everywhere, often also in the used crates, just to get somewhat of an idea.

#

All that assumes that cargo run also didn't show errors. At least until recently tauri dev was hiding a few errors as well (rarely) but that shouldn't happen anymore.