{"record":{"id":"76a6b5fead45f985","repo":"rustdesk/rustdesk","slug":"failed-to-get-decode-context","errorCode":null,"errorMessage":"Failed to get decode context","messagePattern":"Failed to get decode context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libs/scrap/src/common/vram.rs","lineNumber":356,"sourceCode":"            .vram_decode\n            .drain(..)\n            .filter(|c| c.data_format == data_format && c.luid == luid && luid != 0)\n            .collect()\n    }\n\n    pub fn possible_available_without_check() -> (bool, bool) {\n        if !enable_vram_option(false) {\n            return (false, false);\n        }\n        let v = crate::hwcodec::HwCodecConfig::get().vram_decode;\n        (\n            v.iter().any(|d| d.data_format == DataFormat::H264),\n            v.iter().any(|d| d.data_format == DataFormat::H265),\n        )\n    }\n\n    pub fn new(format: CodecFormat, luid: Option<i64>) -> ResultType<Self> {\n        let ctx = Self::try_get(format, luid).ok_or(anyhow!(\"Failed to get decode context\"))?;\n        log::info!(\"try create vram decoder: {ctx:?}\");\n        match Decoder::new(ctx) {\n            Ok(decoder) => Ok(Self { decoder }),\n            Err(_) => {\n                HwCodecConfig::clear(true, false);\n                Err(anyhow!(format!(\n                    \"Failed to create decoder, format: {:?}\",\n                    format\n                )))\n            }\n        }\n    }\n    pub fn decode<'a>(&'a mut self, data: &[u8]) -> ResultType<Vec<VRamDecoderImage<'a>>> {\n        match self.decoder.decode(data) {\n            Ok(v) => Ok(v.iter().map(|f| VRamDecoderImage { frame: f }).collect()),\n            Err(e) => Err(anyhow!(e)),\n        }\n    }","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/rustdesk/rustdesk/blob/91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540/libs/scrap/src/common/vram.rs#L338-L374","documentation":"VramDecoder::new first calls try_get(format, luid) to find a usable hardware decode context (a device/format combination matching the requested codec and optional LUID). If no context matches, `ok_or` produces `Failed to get decode context`. The requested hardware decoding configuration has no candidate on this machine.","triggerScenarios":"Constructing VramDecoder::new(format, luid) where try_get returns None — no adapter/dxgi device supports the requested CodecFormat, or the supplied luid does not match any detected decode-capable adapter.","commonSituations":"Remote machine GPU lacks H264/H265 hardware decode (or drivers are too old); the peer negotiated a codec the local GPU cannot hardware-decode; stale HwCodecConfig cache lists adapters that no longer exist (driver update, dock/monitor change); passing a luid from a different adapter than the capture one.","solutions":["Fall back to software decoding when VramDecoder::new fails, using the negotiated codec's software path.","Check GPU capability/driver support for the requested codec format before attempting hardware decode (supported_decodings / codec capability checks).","Clear the cached HwCodecConfig (the code already clears on decoder-create failure) so adapter detection re-runs, then retry.","Verify the luid passed matches the adapter actually used for capture/decode; pass None to let try_get pick any capable adapter."],"exampleFix":"// before\nlet decoder = VramDecoder::new(format, Some(luid))?;\n// after\nlet decoder = match VramDecoder::new(format, Some(luid)) {\n    Ok(d) => d,\n    Err(e) => {\n        log::warn!(\"vram decode unavailable ({e}), using software decoder\");\n        Decoder::new_software(format)?\n    }\n};","handlingStrategy":"fallback","validationCode":"let can_hw_decode = supported_decodings()\n    .iter()\n    .any(|d| d.codec_format == format);\nif !can_hw_decode {\n    // construct software decoder instead of VramDecoder::new\n}","typeGuard":null,"tryCatchPattern":"// Rust: match on Result\nmatch VramDecoder::new(format, luid) {\n    Ok(d) => d,\n    Err(e) if e.to_string().contains(\"Failed to get decode context\") => {\n        log::warn!(\"no hw decode ctx for {format:?}, software fallback\");\n        Decoder::new_software(format)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Query hardware decode capabilities before negotiating a codec with the peer","Pass None for luid unless you specifically need to pin the decode adapter","Refresh cached HwCodecConfig after driver updates or adapter changes"],"tags":["video-decoding","hardware-codec","gpu","rust"],"backgroundTag":"resource-not-found","analyzedSha":"91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540","analyzedAt":"2026-09-10T19:53:44.083Z","contentChangedAt":"2026-09-10T19:53:44.083Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}