{"record":{"id":"a79446859f2f7a60","repo":"FyroxEngine/Fyrox","slug":"error-while-setting-decoder-position","errorCode":null,"errorMessage":"error while setting decoder position","messagePattern":"error while setting decoder position","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"fyrox-sound/src/source.rs","lineNumber":474,"sourceCode":"            if let Some(buffer) = buffer.state().data() {\n                return Duration::from_secs_f64(self.playback_pos / (buffer.sample_rate() as f64));\n            }\n        }\n\n        Duration::from_secs(0)\n    }\n\n    /// Sets playback duration.\n    pub fn set_playback_time(&mut self, time: Duration) {\n        if let Some(buffer) = self.buffer.as_ref() {\n            if let Some(buffer) = buffer.state().data() {\n                if let SoundBuffer::Streaming(ref mut streaming) = *buffer {\n                    // Make sure decoder is at right position.\n                    if streaming\n                        .time_seek(time.clamp(Duration::from_secs(0), streaming.duration()))\n                        .is_err()\n                    {\n                        Log::warn(\"error while setting decoder position\");\n                    }\n                }\n                // Set absolute position first.\n                self.playback_pos = (time.as_secs_f64() * buffer.sample_rate as f64)\n                    .clamp(0.0, buffer.duration().as_secs_f64());\n                // Then adjust buffer read position.\n                self.buf_read_pos = match *buffer {\n                    SoundBuffer::Streaming(ref mut streaming) => {\n                        // Make sure to load correct data into buffer from decoder.\n                        streaming.read_next_block();\n                        // Streaming sources has different buffer read position because\n                        // buffer contains only small portion of data.\n                        self.playback_pos % (StreamingBuffer::STREAM_SAMPLE_COUNT as f64)\n                    }\n                    SoundBuffer::Generic(_) => self.playback_pos,\n                };\n                assert!(\n                    self.buf_read_pos * (buffer.channel_count() as f64)","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-sound/src/source.rs#L456-L492","documentation":"For streaming sound buffers, set_playback_time seeks the underlying decoder to the requested time. If the decoder cannot seek (time_seek returns Err), the position is not applied and a warning is logged; playback position tracking still continues from the clamped value.","triggerScenarios":"Calling GenericSourceBuilder::build with a play time, or set_playback_time, on a streaming buffer whose decoder does not support seeking to that offset (or seek fails for format reasons).","commonSituations":"Streaming compressed audio (OGG/MP3) with decoders lacking full seek support; requesting a time beyond/near the buffer duration in edge cases; malformed audio files.","solutions":["Prefer loading the buffer as non-streaming (immutable) if seeking is required","Check the audio file is valid and its decoder supports seek","Clamp requested playback time within [0, duration] before building the source","Downgrade severity expectations: playback continues from current decoder position"],"exampleFix":"// before\nlet src = GenericSourceBuilder::new(buffer).with_play_time(desired_time).build()?;\n// after\nlet time = desired_time.clamp(Duration::ZERO, buffer.duration());\nlet src = GenericSourceBuilder::new(buffer).with_play_time(time).build()?; // and consider non-streaming buffer if seek is essential","handlingStrategy":"validation","validationCode":"let t = requested.clamp(Duration::ZERO, buffer.duration());\n// prefer non-streaming buffer when seek support matters\nlet buffer = SoundBuffer::from_file(path)?; // vs raw streaming","typeGuard":"fn seekable(b: &SoundBuffer) -> bool { !matches!(b, SoundBuffer::Streaming(_)) }","tryCatchPattern":null,"preventionTips":["Use non-streaming buffers when random access/seek is required","Clamp playback time to [0, duration] before set_playback_time","Verify audio files decode correctly with a standalone decoder"],"tags":["audio","streaming","seek"],"backgroundTag":"unsupported-operation","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}