Skip to content

Seeking SamplesBuffer to position 0 panics #923

Description

@AnteDeliria

When seeking rodio::buffer::SamplesBuffer to Duration::from_secs(0), a panic occurs:

use rodio::nz;
use rodio::buffer::SamplesBuffer;
use std::time::Duration;
let mut buffer = SamplesBuffer::new(nz!(2), nz!(44100), vec![0.0, 0.0, 0.0, 0.0, 0.0, 0.0]);
buffer.next();
buffer.try_seek(Duration::from_secs(0));

Error message:

[windows] thread 'main' (23364) panicked at C:\Users\User\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rodio-0.22.2\src\buffer.rs:116:23:
[windows] attempt to subtract with overflow

The line where it happens:

// make sure the next sample is for the right channel
let new_pos = new_pos.next_multiple_of(self.channels().get() as usize);
let new_pos = new_pos - curr_channel;

It looks like curr_channel is being subtracted from new_pos, which in this case is equal to 0, causing an underflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions