{"record":{"id":"e5911743f3a513a9","repo":"wailsapp/wails","slug":"create-image-list-failed","errorCode":null,"errorMessage":"Create image list failed","messagePattern":"Create image list failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/pkg/w32/comctl32.go","lineNumber":45,"sourceCode":")\n\nfunc InitCommonControlsEx(lpInitCtrls *INITCOMMONCONTROLSEX) bool {\n\tret, _, _ := procInitCommonControlsEx.Call(\n\t\tuintptr(unsafe.Pointer(lpInitCtrls)))\n\n\treturn ret != 0\n}\n\nfunc ImageList_Create(cx, cy int, flags uint, cInitial, cGrow int) HIMAGELIST {\n\tret, _, _ := procImageList_Create.Call(\n\t\tuintptr(cx),\n\t\tuintptr(cy),\n\t\tuintptr(flags),\n\t\tuintptr(cInitial),\n\t\tuintptr(cGrow))\n\n\tif ret == 0 {\n\t\tpanic(\"Create image list failed\")\n\t}\n\n\treturn HIMAGELIST(ret)\n}\n\nfunc ImageList_Destroy(himl HIMAGELIST) bool {\n\tret, _, _ := procImageList_Destroy.Call(\n\t\tuintptr(himl))\n\n\treturn ret != 0\n}\n\nfunc ImageList_GetImageCount(himl HIMAGELIST) int {\n\tret, _, _ := procImageList_GetImageCount.Call(\n\t\tuintptr(himl))\n\n\treturn int(ret)\n}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v3/pkg/w32/comctl32.go#L27-L63","documentation":"ImageList_Create is a thin wrapper over the Win32 comctl32 ImageList_Create API in Wails' internal w32 package; it panics when the native call returns NULL, meaning image-list creation failed entirely. In the current v3 tree it has no callers (it was inherited from v2's winc layer, where it backs toolbar/imagelist helpers), so in practice only code that imports and calls v3/pkg/w32 directly can hit it.","triggerScenarios":"Calling w32.ImageList_Create with invalid arguments: cx or cy <= 0, an unknown flags combination, or cInitial/cGrow values that overflow on 32-bit; or legitimately failing at the OS level (out of memory, comctl32 not available in the session, e.g. some server/service contexts).","commonSituations":"Custom Win32 integration code reusing Wails' w32 helpers; headless/service sessions lacking a common-controls-capable desktop; porting v2 winc-based drawing code into v3.","solutions":["Validate arguments before calling: cx > 0, cy > 0, flags limited to ILC_* constants (e.g. ILC_COLOR32), and modest cInitial/cGrow","If you control the call site, check the returned handle instead of using this wrapper, or copy the wrapper and return an error rather than panicking","In restricted sessions (services/RDP disconnected), initialize common controls (InitCommonControlsEx) first and ensure a desktop heap is available"],"exampleFix":"// before\nhiml := w32.ImageList_Create(0, 16, w32.ILC_COLOR32, 4, 4) // cx=0 -> native NULL -> panic\n\n// after\nhiml := w32.ImageList_Create(16, 16, w32.ILC_COLOR32, 4, 4) // valid size","handlingStrategy":"validation","validationCode":"func createImageList(cx, cy, cInitial, cGrow int, flags uint) (w32.HIMAGELIST, bool) {\n\tif cx <= 0 || cy <= 0 || cInitial < 0 || cGrow < 0 {\n\t\treturn 0, false\n\t}\n\treturn w32.ImageList_Create(cx, cy, flags, cInitial, cGrow), true\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tlog.Printf(\"ImageList_Create failed: %v\", r)\n\t}\n}()\nhiml := w32.ImageList_Create(16, 16, w32.ILC_COLOR32, 4, 4)","preventionTips":["Always pass positive cx/cy and ILC_* flags from the w32 package","Verify common controls are initialized in the process before creating image lists","Avoid calling internal w32 helpers from service/headless sessions without a desktop"],"tags":["windows","win32","comctl32","image-list","panic","native"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}