{"record":{"id":"ad3b96409ed61ea0","repo":"JanDeDobbeleer/oh-my-posh","slug":"roinitialize-0x-08x","errorCode":null,"errorMessage":"RoInitialize: 0x%08x","messagePattern":"RoInitialize: 0x%08x","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/runtime/smtc_windows.go","lineNumber":229,"sourceCode":"\t\t}\n\t\tif time.Now().After(deadline) {\n\t\t\treturn errors.New(\"async timed out\")\n\t\t}\n\t\ttime.Sleep(smtcAsyncPollInterval)\n\t}\n}\n\nfunc queryMediaPlayer(player string) (*MediaInfo, error) {\n\t// RoInitialize / RoUninitialize update thread-local state, so we have to\n\t// pin the goroutine to one OS thread for the duration of this call.\n\tgoruntime.LockOSThread()\n\tdefer goruntime.UnlockOSThread()\n\n\t// RO_INIT_MULTITHREADED = 1. S_FALSE (1) means already initialised on\n\t// this thread, which is fine — we still pair with RoUninitialize.\n\thr, _, _ := procRoInitialize.Call(1)\n\tif hr != 0 && hr != 1 {\n\t\treturn nil, fmt.Errorf(\"RoInitialize: 0x%08x\", hr)\n\t}\n\tdefer func() { _, _, _ = procRoUninitialize.Call() }()\n\n\tclassID, err := newHString(\"Windows.Media.Control.GlobalSystemMediaTransportControlsSessionManager\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer classID.Close()\n\n\tvar factory unsafe.Pointer\n\thr, _, _ = procRoGetActivationFactory.Call(\n\t\tuintptr(classID),\n\t\tuintptr(unsafe.Pointer(&iidSMTCSessionManagerStatics)),\n\t\tuintptr(unsafe.Pointer(&factory)),\n\t)\n\tif hr != 0 {\n\t\treturn nil, fmt.Errorf(\"RoGetActivationFactory: 0x%08x\", hr)\n\t}","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/smtc_windows.go#L211-L247","documentation":"Before touching any WinRT API, the SMTC media player code calls RoInitialize with RO_INIT_MULTITHREADED on the locked OS thread. S_FALSE (1) means the thread was already initialized and is accepted; any other non-zero HRESULT is returned as this error, meaning WinRT could not be initialized on this thread and no media info can be queried.","triggerScenarios":"QueryMediaPlayer calling procRoInitialize and getting an HRESULT other than 0 (S_OK) or 1 (S_FALSE) - e.g. E_OUTOFMEMORY (0x8007000E) or E_CHANGEDMODE (0x80010106) when the thread is already initialized in a different apartment mode.","commonSituations":"Embedding oh-my-posh in a host process that already initialized COM on the thread as STA (single-threaded apartment); extremely low-memory conditions (E_OUTOFMEMORY); unusual threading environments in custom prompt hosts.","solutions":["If the HRESULT is 0x80010106 (E_CHANGEDMODE), run the prompt in a thread/process that has not pre-initialized COM as STA, or accept the media segment being unavailable","Retry after freeing memory if the code is E_OUTOFMEMORY","Check the host application's COM apartment model if embedding oh-my-posh","Update Windows if the failure persists on a clean thread"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"info, err := runtime.QueryMediaPlayer(env)\nif err != nil {\n\tvar hrErr interface{ HRESULT() uint32 }\n\tif errors.As(err, &hrErr) { /* inspect RoInitialize HRESULT */ }\n\treturn mediaSegment{} // hide segment, prompt keeps rendering\n}","preventionTips":["Don't embed the prompt in hosts that pre-initialize COM as STA on the render thread","Accept/hide the media segment when E_CHANGEDMODE or OOM HRESULTs appear","Retry once on transient OOM (0x8007000E) before giving up","Test media segments in a clean shell, not inside custom COM-hosting apps"],"tags":["windows","winrt","com","threading"],"backgroundTag":"winrt-hresult-error","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}