Skip to content
New issue

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

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

Already on GitHub? # to your account

Looping issues w/ segfault #32

Open
bamidev opened this issue Jul 23, 2023 · 1 comment
Open

Looping issues w/ segfault #32

bamidev opened this issue Jul 23, 2023 · 1 comment

Comments

@bamidev
Copy link

bamidev commented Jul 23, 2023

Describe the bug
I'm using soloud-rs to mix some ambience tracks together. However, I've noticed that even though I use set_looping to enable looping on all tracks, they don't seem to loop though. Moreover, when I use an mp3 file for it, it causes a Segmentationfault at the end of the loop.
It's very peculiar that my mp3 files cause segfaults and my flac files don't. I've tested multiple mp3 and flac files, multiple times each, and it seems to be pretty consistent.

To Reproduce
So here is how I load the files and play them:

        fn play_soundscape(runtime: &Runtime, sl: &mut Soloud, track: &mut Track, filename: &str, volume: f64) -> Result<(), SoloudError> {
		// Fade out old sound if still playing
		Self::clear_track(runtime, sl, track);

		eprintln!("Playing: {} ({}%)", filename, (volume*100.0) as u32);
		
		// Load and fade in new sound
		let mut filepath = PathBuf::new();
		filepath.push(SOUNDSCAPES_DIR);
		filepath.push(filename);
		let mut wav = Box::pin(WavStream::default());
		wav.load(filepath)?;
		wav.set_volume(0.0);
		let new_handle = sl.play(&*wav);
		sl.fade_volume(new_handle, volume as f32, 30.0);
		sl.set_loop_point(new_handle, 0.0);
		sl.set_looping(new_handle, true);
		track.handle = Some(new_handle);
		track.stream = Some(UnsafeSend::new(wav));
		Ok(())
	}

Expected behavior
I expect the files that I'm playing to restart from the beginning when they are done

Desktop (please complete the following information):

  • OS: Debian w/ 5.10.0 kernel
@MoAlyousef
Copy link
Owner

Hi

I'm running ubuntu in WSL, and I can't seem to reproduce the issue.
I've updated soloud to latest master. So can you try with the master branch:

[dependencies]
soloud = { git = "https://github.com/MoAlyousef/soloud-rs" }

I tried to recreate some aspects of the code:

use soloud::*;
use std::pin::Pin;
use unsafe_send_sync::UnsafeSend;

#[derive(Default)]
struct Track {
    handle: Option<Handle>,
    stream: Option<UnsafeSend<Pin<Box<soloud::Wav>>>>,
}

fn play_soundscape(sl: &mut Soloud, track: &mut Track, filename: &str, volume: f32) -> Result<(), Box<dyn std::error::Error>> {
    let mut wav = Box::pin(audio::Wav::default());
    wav.load(filename)?;
    let new_handle = sl.play(&*wav);
    sl.set_pause(new_handle, true);
    sl.fade_volume(new_handle, volume, 30.0);
    sl.set_loop_point(new_handle, 0.0);
    sl.set_looping(new_handle, true);
    track.handle = Some(new_handle);
    track.stream = Some(UnsafeSend::new(wav));
    Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut sl = Soloud::default()?;
    sl.set_global_volume(3.0);
    let mut track = Track::default();
    play_soundscape(&mut sl, &mut track, "song.mp3", 10.).unwrap();
    sl.set_pause(track.handle.unwrap(), false);
    while sl.voice_count() > 0 {
        std::thread::sleep(std::time::Duration::from_millis(100));
    }
    Ok(())
}

Does this code exhibit the faulty behavior? It should be a minimal repro

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants