rustdesk/rustdesk · error
Failed to get decode context
Error message
Failed to get decode context
What it means
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.
Source
Thrown at libs/scrap/src/common/vram.rs:356
.vram_decode
.drain(..)
.filter(|c| c.data_format == data_format && c.luid == luid && luid != 0)
.collect()
}
pub fn possible_available_without_check() -> (bool, bool) {
if !enable_vram_option(false) {
return (false, false);
}
let v = crate::hwcodec::HwCodecConfig::get().vram_decode;
(
v.iter().any(|d| d.data_format == DataFormat::H264),
v.iter().any(|d| d.data_format == DataFormat::H265),
)
}
pub fn new(format: CodecFormat, luid: Option<i64>) -> ResultType<Self> {
let ctx = Self::try_get(format, luid).ok_or(anyhow!("Failed to get decode context"))?;
log::info!("try create vram decoder: {ctx:?}");
match Decoder::new(ctx) {
Ok(decoder) => Ok(Self { decoder }),
Err(_) => {
HwCodecConfig::clear(true, false);
Err(anyhow!(format!(
"Failed to create decoder, format: {:?}",
format
)))
}
}
}
pub fn decode<'a>(&'a mut self, data: &[u8]) -> ResultType<Vec<VRamDecoderImage<'a>>> {
match self.decoder.decode(data) {
Ok(v) => Ok(v.iter().map(|f| VRamDecoderImage { frame: f }).collect()),
Err(e) => Err(anyhow!(e)),
}
}View on GitHub (pinned to 91c9fccbb0)
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.
Example fix
// before
let decoder = VramDecoder::new(format, Some(luid))?;
// after
let decoder = match VramDecoder::new(format, Some(luid)) {
Ok(d) => d,
Err(e) => {
log::warn!("vram decode unavailable ({e}), using software decoder");
Decoder::new_software(format)?
}
}; Defensive patterns
Strategy: fallback
Validate before calling
let can_hw_decode = supported_decodings()
.iter()
.any(|d| d.codec_format == format);
if !can_hw_decode {
// construct software decoder instead of VramDecoder::new
} Try / catch
// Rust: match on Result
match VramDecoder::new(format, luid) {
Ok(d) => d,
Err(e) if e.to_string().contains("Failed to get decode context") => {
log::warn!("no hw decode ctx for {format:?}, software fallback");
Decoder::new_software(format)?
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- unsupported format: {:?} -> {:?}
- Failed to create decoder, format: {:?}
- not texture frame
- encoder type mismatch
- rotation not supported
AI-assisted analysis of rustdesk/rustdesk@91c9fccbb0 (2026-09-10).
Data as JSON: /api/errors/76a6b5fead45f985.
Report an issue: GitHub.