{"record":{"id":"e77cc6e22b8c9fc5","repo":"gfx-rs/wgpu","slug":"com-pointer-should-not-be-null","errorCode":null,"errorMessage":"COM pointer should not be NULL","messagePattern":"COM pointer should not be NULL","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-hal/src/dx12/mod.rs","lineNumber":442,"sourceCode":"    supports_allow_tearing: bool,\n    presentation_system: wgt::Dx12SwapchainKind,\n    _lib_dxgi: DxgiLib,\n    flags: wgt::InstanceFlags,\n    memory_budget_thresholds: wgt::MemoryBudgetThresholds,\n    compiler_container: Arc<shader_compilation::CompilerContainer>,\n    options: wgt::Dx12BackendOptions,\n    telemetry: Option<crate::Telemetry>,\n}\n\nimpl Instance {\n    /// Get the raw DXGI factory associated with this instance.\n    pub unsafe fn raw_factory4(&self) -> &Dxgi::IDXGIFactory4 {\n        self.factory.deref()\n    }\n\n    pub unsafe fn create_surface_from_visual(&self, visual: *mut ffi::c_void) -> Surface {\n        let visual = unsafe { DirectComposition::IDCompositionVisual::from_raw_borrowed(&visual) }\n            .expect(\"COM pointer should not be NULL\");\n        Surface {\n            factory: self.factory.clone(),\n            factory_media: self.factory_media.clone(),\n            target: SurfaceTarget::Visual(visual.to_owned()),\n            supports_allow_tearing: self.supports_allow_tearing,\n            swap_chain: RwLock::new(None),\n            options: self.options.clone(),\n            hdr_source: None,\n        }\n    }\n\n    pub unsafe fn create_surface_from_surface_handle(\n        &self,\n        surface_handle: *mut ffi::c_void,\n    ) -> Surface {\n        // 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.\n        // https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-duplicatehandle could help us, even though DirectComposition is not in the list?\n        // Or we make all these types owned, require an ownership transition, and replace SurfaceTargetUnsafe with SurfaceTarget.","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-hal/src/dx12/mod.rs#L424-L460","documentation":"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.","triggerScenarios":"Thrown at wgpu-hal/src/dx12/mod.rs:442 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a valid non-null IDCompositionVisual pointer when creating the surface","Check the pointer before calling the unsafe constructor"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}