Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

cpal + dioxus_desktop: eats memory and dies

Aperta
#782 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
32/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Start by reproducing the memory spike with the minimal CPAL stream and Dioxus Desktop launch shown in the issue, then compare each program running alone. The payload names no repository files or tests and does not identify which library causes the interaction, so debugging will require tracing both libraries' startup paths. Done means the combined program opens its window without unbounded memory use while the audio stream runs.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

With latest versions:

cpal = { version = "0.15.2", features=["jack"] }

dioxus = "0.3.2"
dioxus-ssr = "0.3.0"
dioxus-desktop = "0.3.0"

Consider this minimal code:

use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::{BufferSize, Device, Stream, StreamConfig, SupportedBufferSize};
use std::cmp::max;

fn main() {
    let _stream = start_cpal();

    loop {}
}

fn start_cpal() -> Stream {
    let device = get_device();
    let config = get_config(&device);

    let stream = device
        .build_output_stream(
            &config,
            move |_: &mut [f32], _: &cpal::OutputCallbackInfo| {},
            move |_| {},
            None,
        )
        .unwrap();

    stream.play().unwrap();
    stream
}

fn get_device() -> Device {
    let host_id = cpal::available_hosts()[0];
    let host = cpal::host_from_id(host_id).unwrap();

    host.default_output_device().unwrap()
}

fn get_config(device: &Device) -> StreamConfig {
    let mut supported_configs_range = device.supported_output_configs().unwrap();
    let supported_config = supported_configs_range
        .next()
        .unwrap()
        .with_max_sample_rate();

    let mut config = supported_config.config();
    config.buffer_size = BufferSize::Fixed(get_some_buffer_size(supported_config.buffer_size()));

    config
}

fn get_some_buffer_size(spec: &SupportedBufferSize) -> u32 {
    match spec {
        SupportedBufferSize::Range { min, .. } => max(*min, 64),
        SupportedBufferSize::Unknown => 64,
    }
}

It works as expected (program runs; nothing happens). I also get sound if I put something in the data callback.

Enter dioxus desktop:

fn main() {
    let _stream = start_cpal();

    dioxus_desktop::launch(app);
}

use dioxus::prelude::*;
fn app(cx: Scope) -> Element {
    cx.render(rsx!("lol"))
}
// .. same code as before

Expected result: cpal still works; Dioxus window shows up.

Actual result: program eats all the memory and the OS kills it. No window shows up.

Resource monitor screenshot: spike in memory usage

The start of the spike is where I run the program. It falls back down after a few seconds when the process is killed.

The issue is not with Dioxus alone, because this program works as expected:

fn main() {
    dioxus_desktop::launch(app);
}

The problem only occurs when I use cpal and Dioxus in the same program.

I don't know if this is an issue with Dioxus or cpal, and I have no idea where to begin debugging this. Any ideas please?

I'm on Ubuntu 22.04.2 LTS. Lemme know if you need any other details. Thank you!!

Lingua principale
Rust
Stelle
4k
Fork
554
Merge medio
3g 3h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di RustAudio/cpal

Tutte le issue di RustAudio/cpal

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.