{"record":{"id":"b81627fa95d5ab0e","repo":"neovide/neovide","slug":"could-not-create-composition-target","errorCode":null,"errorMessage":"Could not create composition target","messagePattern":"Could not create composition target","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/renderer/d3d.rs","lineNumber":201,"sourceCode":"            tracy_zone!(\"create swap_chain\");\n            dxgi_factory\n                .CreateSwapChainForComposition(&command_queue, &swap_chain_desc, None)\n                .expect(\"Failed to create the Direct3D swap chain\")\n        };\n\n        let swap_chain: IDXGISwapChain3 =\n            IDXGISwapChain1::cast(&swap_chain).expect(\"Failed to cast\");\n\n        unsafe {\n            swap_chain.SetMaximumFrameLatency(1).expect(\"Failed to set maximum frame latency\");\n        }\n        let composition_device: IDCompositionDevice = unsafe {\n            DCompositionCreateDevice2(None).expect(\"Could not create composition device\")\n        };\n        let target = unsafe {\n            composition_device\n                .CreateTargetForHwnd(hwnd, true)\n                .expect(\"Could not create composition target\")\n        };\n        let visual = unsafe {\n            composition_device.CreateVisual().expect(\"Could not create composition visual\")\n        };\n\n        unsafe {\n            visual.SetContent(&swap_chain).expect(\"Failed to set composition content\");\n            target.SetRoot(&visual).expect(\"Failed to set composition root\");\n            composition_device.Commit().expect(\"Failed to commit composition\");\n        }\n\n        let swap_chain_waitable = unsafe { swap_chain.GetFrameLatencyWaitableObject() };\n        if swap_chain_waitable.is_invalid() {\n            panic!(\"Failed to get swapchain waitable object\");\n        }\n\n        // use a high value to make it easier to track these in PIX\n        let fence_values = vec![10000; swap_chain_desc.BufferCount as usize];","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/neovide/neovide/blob/ade2d9cda777879975b1852f77dc672f5ff43b78/src/renderer/d3d.rs#L183-L219","documentation":"Thrown when IDCompositionDevice::CreateTargetForHwnd(hwnd, true) fails. This creates a composition target bound to the given top-level window; the 'true' flag means topmost. Failure occurs when the HWND is invalid, not a top-level window, already has a composition target (from another device), or access is denied (different integrity level / UIPI).","triggerScenarios":"HWND is child/control window instead of a top-level window; another IDCompositionDevice already created a target for the same HWND; hwnd handle invalid or belongs to another process with higher integrity; running elevated vs non-elevated mismatch.","commonSituations":"Passing a winit child window handle; two renderer instances for one window; mixed elevation (app elevated, window created unelevated or vice versa).","solutions":["Ensure hwnd is a top-level window (use the winit outer window handle, not a child)","Close/release any previous composition target for the same HWND before creating a new one","Recreate the renderer rather than calling new twice on the same window","Run the app at the same or higher integrity level than the window's owner"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn is_top_level_window(hwnd: HWND) -> bool {\n    unsafe { GetAncestor(hwnd, GA_ROOT) == hwnd && IsWindow(hwnd).as_bool() }\n}\n// call before CreateTargetForHwnd\nassert!(is_top_level_window(hwnd), \"CreateTargetForHwnd needs a top-level HWND\");","typeGuard":null,"tryCatchPattern":"let target = composition_device.CreateTargetForHwnd(hwnd, true)\n    .map_err(|e| { log::error!(\"CreateTargetForHwnd({hwnd:?}) failed: {e}\"); RendererInitError::Target(e) })?;","preventionTips":["Use the outer/top-level winit window handle, never a child HWND","Only create one composition target per HWND per process; drop it before re-creating","Match integrity levels (don't mix elevated/unelevated across process and window owner)","Recreate the renderer instead of double-initializing the same window"],"tags":["directx","directcomposition","hwnd","windows"],"backgroundTag":"invalid-argument-value","analyzedSha":"ade2d9cda777879975b1852f77dc672f5ff43b78","analyzedAt":"2026-09-06T04:14:57.389Z","contentChangedAt":"2026-09-06T04:14:57.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}