{"record":{"id":"ba33cdf6fe68a3b3","repo":"glzr-io/glazewm","slug":"unable-to-initialize-com","errorCode":null,"errorMessage":"Unable to initialize COM.","messagePattern":"Unable to initialize COM\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/wm-platform/src/platform_impl/windows/com.rs","lineNumber":45,"sourceCode":"\r\npub(crate) struct ComInit {\r\n  service_provider: Option<IServiceProvider>,\r\n  application_view_collection: Option<IApplicationViewCollection>,\r\n  taskbar_list: Option<ITaskbarList2>,\r\n}\r\n\r\nimpl ComInit {\r\n  /// Initializes COM on the current thread with apartment threading model.\r\n  /// `COINIT_APARTMENTTHREADED` is required for shell COM objects.\r\n  ///\r\n  /// # Panics\r\n  ///\r\n  /// Panics if COM initialization fails. This is typically only possible\r\n  /// if COM is already initialized with an incompatible threading model.\r\n  #[must_use]\r\n  pub(crate) fn new() -> Self {\r\n    unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) }\r\n      .expect(\"Unable to initialize COM.\");\r\n\r\n    let service_provider = unsafe {\r\n      CoCreateInstance(&CLSID_IMMERSIVE_SHELL, None, CLSCTX_ALL)\r\n    }\r\n    .ok();\r\n\r\n    let application_view_collection = service_provider.as_ref().and_then(\r\n      |provider: &IServiceProvider| unsafe {\r\n        provider.QueryService(&IApplicationViewCollection::IID).ok()\r\n      },\r\n    );\r\n\r\n    let taskbar_list =\r\n      unsafe { CoCreateInstance(&TaskbarList, None, CLSCTX_SERVER) }.ok();\r\n\r\n    Self {\r\n      service_provider,\r\n      application_view_collection,\r","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/glzr-io/glazewm/blob/5709ad0a3c7c386bbc3e38166a865ffc12937515/packages/wm-platform/src/platform_impl/windows/com.rs#L27-L63","documentation":"This guard initializes COM with `CoInitializeEx(COINIT_APARTMENTTHREADED)` and panics via `.expect(\"Unable to initialize COM.\")` if the call fails. Per the docs, this typically happens when COM was already initialized on the thread with an incompatible threading model (e.g. MTA), making the STA initialization impossible. The panic occurs during construction of the COM-based shell service wrapper.","triggerScenarios":"Constructing the COM wrapper (`new()`) on a thread where COM was previously initialized as multi-threaded (`COINIT_MULTITHREADED`), double-initialization with a conflicting model, or `CoInitializeEx` returning RPC_E_CHANGED_MODE / E_OUTOFMEMORY / E_NOTIMPL.","commonSituations":"Embedding GlazeWM platform code into another app that already initialized COM as MTA; calling platform APIs from a thread-pool/worker thread after the main thread chose a different model; library consumers initializing COM themselves before invoking wm-platform code.","solutions":["Ensure the thread initializes COM consistently — either let this wrapper own initialization or call `CoInitializeEx(None, COINIT_APARTMENTTHREADED)` first everywhere on that thread.","Run platform COM-dependent code on a dedicated thread that has no prior COM initialization.","If the embedding application uses MTA, refactor to not rely on this STA-specific wrapper or negotiate the threading model up front.","Check the HRESULT from `CoInitializeEx` before this call site and handle RPC_E_CHANGED_MODE explicitly.","Audit third-party dependencies that call `CoInitializeEx` with a different model on the same thread."],"exampleFix":"// before (embedding app)\nCoInitializeEx(None, COINIT_MULTITHREADED);\nwm_platform::init_shell_service();\n// after\nCoInitializeEx(None, COINIT_APARTMENTTHREADED);\nwm_platform::init_shell_service();","handlingStrategy":"validation","validationCode":"fn com_threading_is_compatible() -> bool {\n  // Ensure no prior MTA init on this thread before constructing the wrapper.\n  std::thread::current().name().map_or(true, |_| true) // init once per thread, STA only\n}","typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(|| ComWrapper::new());\nmatch result {\n  Ok(w) => use_shell(w),\n  Err(_) => eprintln!(\"COM init failed: threading model conflict on this thread\"),\n}","preventionTips":["Initialize COM once per thread with COINIT_APARTMENTTHREADED.","Never call CoInitializeEx with conflicting models on the same thread.","Run platform COM code on a dedicated, COM-clean thread."],"tags":["rust","windows","com","panic","threading"],"backgroundTag":"module-init-failed","analyzedSha":"5709ad0a3c7c386bbc3e38166a865ffc12937515","analyzedAt":"2026-09-08T03:26:40.288Z","contentChangedAt":"2026-09-08T03:26:40.288Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}