gfx-rs/wgpu · error
COM pointer should not be NULL
Error message
COM pointer should not be NULL
What it means
Panic in the DX12 backend's create_surface_from_visual: the passed raw pointer for the Windows UI Composition visual is NULL, so the DCompositionSurface cannot be retrieved. The faulty input is the null visual pointer.
Source
Thrown at wgpu-hal/src/dx12/mod.rs:442
supports_allow_tearing: bool,
presentation_system: wgt::Dx12SwapchainKind,
_lib_dxgi: DxgiLib,
flags: wgt::InstanceFlags,
memory_budget_thresholds: wgt::MemoryBudgetThresholds,
compiler_container: Arc<shader_compilation::CompilerContainer>,
options: wgt::Dx12BackendOptions,
telemetry: Option<crate::Telemetry>,
}
impl Instance {
/// Get the raw DXGI factory associated with this instance.
pub unsafe fn raw_factory4(&self) -> &Dxgi::IDXGIFactory4 {
self.factory.deref()
}
pub unsafe fn create_surface_from_visual(&self, visual: *mut ffi::c_void) -> Surface {
let visual = unsafe { DirectComposition::IDCompositionVisual::from_raw_borrowed(&visual) }
.expect("COM pointer should not be NULL");
Surface {
factory: self.factory.clone(),
factory_media: self.factory_media.clone(),
target: SurfaceTarget::Visual(visual.to_owned()),
supports_allow_tearing: self.supports_allow_tearing,
swap_chain: RwLock::new(None),
options: self.options.clone(),
hdr_source: None,
}
}
pub unsafe fn create_surface_from_surface_handle(
&self,
surface_handle: *mut ffi::c_void,
) -> Surface {
// TODO: We're not given ownership, so we shouldn't call HANDLE::free(). This puts an extra burden on the caller to keep it alive.
// https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-duplicatehandle could help us, even though DirectComposition is not in the list?
// Or we make all these types owned, require an ownership transition, and replace SurfaceTargetUnsafe with SurfaceTarget.View on GitHub (pinned to 3e11ff59bf)
Solutions
- Pass a valid non-null IDCompositionVisual pointer when creating the surface
- Check the pointer before calling the unsafe constructor
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at wgpu-hal/src/dx12/mod.rs:442 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03).
Data as JSON: /api/errors/e77cc6e22b8c9fc5.
Report an issue: GitHub.