{"record":{"id":"48ded1e541694097","repo":"wailsapp/wails","slug":"failed-to-init-gtk","errorCode":null,"errorMessage":"failed to init GTK","messagePattern":"failed to init GTK","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"v2/internal/frontend/desktop/linux/frontend.go","lineNumber":182,"sourceCode":"func (f *Frontend) RunMainLoop() {\n\tC.gtk_main()\n}\n\nfunc (f *Frontend) WindowClose() {\n\tf.mainWindow.Destroy()\n}\n\nfunc NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {\n\tinitOnce.Do(func() {\n\t\truntime.LockOSThread()\n\n\t\t// Set GDK_BACKEND=x11 if currently unset and XDG_SESSION_TYPE is unset, unspecified or x11 to prevent warnings\n\t\tif os.Getenv(\"GDK_BACKEND\") == \"\" && (os.Getenv(\"XDG_SESSION_TYPE\") == \"\" || os.Getenv(\"XDG_SESSION_TYPE\") == \"unspecified\" || os.Getenv(\"XDG_SESSION_TYPE\") == \"x11\") {\n\t\t\t_ = os.Setenv(\"GDK_BACKEND\", \"x11\")\n\t\t}\n\n\t\tif ok := C.gtk_init_check(nil, nil); ok != 1 {\n\t\t\tpanic(errors.New(\"failed to init GTK\"))\n\t\t}\n\t})\n\n\tresult := &Frontend{\n\t\tfrontendOptions: appoptions,\n\t\tlogger:          myLogger,\n\t\tbindings:        appBindings,\n\t\tdispatcher:      dispatcher,\n\t\tctx:             ctx,\n\t}\n\tresult.startURL, _ = url.Parse(startURL)\n\tresult.originValidator = originvalidator.NewOriginValidator(result.startURL, appoptions.BindingsAllowedOrigins)\n\n\tif _starturl, _ := ctx.Value(\"starturl\").(*url.URL); _starturl != nil {\n\t\tresult.startURL = _starturl\n\t\tresult.originValidator = originvalidator.NewOriginValidator(result.startURL, appoptions.BindingsAllowedOrigins)\n\t} else {\n\t\tif port, _ := ctx.Value(\"assetserverport\").(string); port != \"\" {","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v2/internal/frontend/desktop/linux/frontend.go#L164-L200","documentation":"CoCreateInstance panics with 'E_OUTOFMEMORY' in the w32 wrapper when the COM activation could not allocate memory. For out-of-process servers this can mean the server process could not be started due to resource limits; for in-process servers it is straightforward allocation failure. As with other COM memory failures, the arguments were acceptable and the system was simply out of resources.","triggerScenarios":"Activating a COM class while the process is at its commit limit; launching a LocalServer COM executable (e.g. an Office or shell component) on a machine with exhausted desktop heap or process slots; large numbers of simultaneous COM activations from worker goroutines.","commonSituations":"Batch operations that instantiate shell COM objects (thumbnails, notifications) in parallel on memory-tight machines; CI runners with low memory ceilings where local testing passed but the runner panics.","solutions":["Reduce memory pressure before activation: drop caches, free large buffers.","Throttle concurrent CoCreateInstance calls with a semaphore instead of unbounded parallelism.","For local-server classes, verify the server executable can launch (permissions, desktop heap) — check Event Viewer for DCOM errors.","Recover() and retry once after debug.FreeOSMemory() if transient pressure is expected."],"exampleFix":"// before\nfor _, item := range items {\n\tgo func(){ CoCreateInstance(&clsid, CLSCTX_ALL, &riid, ppv) }() // unbounded -> OOM panic\n}\n\n// after\nsem := make(chan struct{}, 4)\nfor _, item := range items {\n\tsem <- struct{}{}\n\tgo func(){ defer func(){ <-sem }(); CoCreateInstance(&clsid, CLSCTX_ALL, &riid, ppv) }()\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"func createCOMObject(clsid, riid *syscall.GUID, ppv uintptr) (err error) {\n\tfor attempt := 0; attempt < 3; attempt++ {\n\t\tok := func() bool {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tif msg, _ := r.(string); strings.Contains(msg, \"E_OUTOFMEMORY\") {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tpanic(r)\n\t\t\t\t}\n\t\t\t}()\n\t\t\tCoCreateInstance(clsid, w32.CLSCTX_ALL, riid, ppv)\n\t\t\treturn true\n\t\t}()\n\t\tif ok {\n\t\t\treturn nil\n\t\t}\n\t\tdebug.FreeOSMemory()\n\t\ttime.Sleep(time.Duration(attempt+1) * 50 * time.Millisecond)\n\t}\n\treturn errors.New(\"com activation failed after retries\")\n}","preventionTips":["Throttle concurrent activations with a semaphore.","Free large caches before COM-heavy batch operations.","For local-server classes, check DCOM event logs for launch failures."],"tags":["windows","com","out-of-memory","syscall","panic"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}