{"record":{"id":"7435c5dce31ec754","repo":"FyroxEngine/Fyrox","slug":"zero-duration-buffer","errorCode":null,"errorMessage":"Zero duration buffer: {:?}","messagePattern":"Zero duration buffer: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"fyrox-sound/src/source.rs","lineNumber":229,"sourceCode":"        buffer: Option<SoundBufferResource>,\n    ) -> Result<Option<SoundBufferResource>, SoundError> {\n        self.buf_read_pos = 0.0;\n        self.playback_pos = 0.0;\n\n        // If we already have streaming buffer assigned make sure to decrease use count\n        // so it can be reused later on if needed.\n        if let Some(buffer) = self.buffer.clone() {\n            if let Some(SoundBuffer::Streaming(streaming)) = buffer.state().data() {\n                streaming.use_count = streaming.use_count.saturating_sub(1);\n            }\n        }\n\n        if let Some(buffer) = buffer.clone() {\n            match buffer.state().data() {\n                None => return Err(SoundError::BufferFailedToLoad),\n                Some(locked_buffer) => {\n                    if locked_buffer.duration() == Duration::ZERO {\n                        panic!(\"Zero duration buffer: {:?}\", locked_buffer);\n                    }\n                    // Check new buffer if streaming - it must not be used by anyone else.\n                    if let SoundBuffer::Streaming(ref mut streaming) = *locked_buffer {\n                        if streaming.use_count != 0 {\n                            return Err(SoundError::StreamingBufferAlreadyInUse);\n                        }\n                        streaming.use_count += 1;\n                    }\n                }\n            }\n        }\n\n        Ok(std::mem::replace(&mut self.buffer, buffer))\n    }\n\n    /// Returns current buffer if any.\n    pub fn buffer(&self) -> Option<SoundBufferResource> {\n        self.buffer.clone()","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-sound/src/source.rs#L211-L247","documentation":"A sound source requires a buffer with non-zero playback length; a zero-duration buffer cannot be played or scheduled. GenericSource::set_buffer checks locked_buffer.duration() and panics with the buffer's debug representation when it is Duration::ZERO (note: a failed load returns SoundError::BufferFailedToLoad instead).","triggerScenarios":"Calling set_buffer(Some(buffer)) on a sound source (directly or via SoundBuilder::build) with a SoundBuffer whose decoded duration is zero — e.g. a 0-byte or empty audio file loaded successfully into an empty buffer.","commonSituations":"Empty/truncated audio files (0-sample wav/ogg) shipped with the game; a generator that produced no samples; file corruption or wrong loader producing empty frames; placeholder audio files never filled in.","solutions":["Replace the audio file with a real, non-empty asset; verify duration > 0 before use.","Check the buffer before assigning: if buffer.duration() == Duration::ZERO, skip/replace it instead of calling set_buffer.","Regenerate or re-export the sound asset and confirm sample count at import time.","If buffers are built procedurally, return SoundError (or skip) when sample data is empty rather than constructing a zero-length buffer."],"exampleFix":"// before\nsource.set_buffer(Some(empty_buffer)); // panics: duration == 0\n// after\nif buffer.duration() > Duration::ZERO {\n    source.set_buffer(Some(buffer));\n} else {\n    eprintln!(\"skipping empty audio buffer\");\n}","handlingStrategy":"validation","validationCode":"fn playable(buffer: &SoundBuffer) -> bool {\n    buffer.duration() > Duration::ZERO\n}\n// only call set_buffer(Some(b)) when playable(&b)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate audio assets (duration/sample count) in CI at import time.","Never ship empty placeholder audio files.","Check buffer duration after loading and before assignment.","For procedural buffers, guard sample count > 0 before constructing SoundBuffer."],"tags":["rust","panic","audio","duration","fyrox-sound"],"backgroundTag":"value-out-of-range","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"}