{"record":{"id":"1f35373ed6c0d1ff","repo":"wailsapp/wails","slug":"unable-to-retrieve-flag-key-e","errorCode":null,"errorMessage":"Unable to retrieve flag '${key}': ${e}","messagePattern":"Unable to retrieve flag '(.+?)': (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/internal/runtime/desktop/@wailsio/runtime/src/flags.ts","lineNumber":21,"sourceCode":"| |\t / /___ _(_) /____\n| | /| / / __ `/ / / ___/\n| |/ |/ / /_/ / / (__  )\n|__/|__/\\__,_/_/_/____/\nThe electron alternative for Go\n(c) Lea Anthony 2019-present\n*/\n\n/**\n * Retrieves the value associated with the specified key from the flag map.\n *\n * @param key - The key to retrieve the value for.\n * @return The value associated with the specified key.\n */\nexport function GetFlag(key: string): any {\n    try {\n        return window._wails.flags[key];\n    } catch (e) {\n        throw new Error(\"Unable to retrieve flag '\" + key + \"': \" + e, { cause: e });\n    }\n}\n","sourceCodeStart":3,"sourceCodeEnd":24,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v3/internal/runtime/desktop/@wailsio/runtime/src/flags.ts#L3-L24","documentation":"StretchBlt copies a rectangle from a source DC into a destination DC, scaling it, and returns FALSE on failure. The w32 wrapper panics with 'StretchBlt failed' on that FALSE. Failure is typically caused by invalid source or destination HDCs, zero/negative extents, or an unsupported combination of rop and color depths (e.g. stretching between DCs of very different formats with certain rop codes). Note StretchBlt also famously succeeds-but-blacks when drivers mishandle it, but the panic path is the explicit FALSE return.","triggerScenarios":"Scaling a screenshot or image whose source memory DC/bitmap was already deleted; passing swapped source/dest width-height so extents are negative; using a rop like SRCAND with incompatible surface formats; calling after the capture DC from GetWindowDC was released.","commonSituations":"Screen-capture or image-resize code in tray/screenshot features; DPI-scaling blits between a 32bpp compatible bitmap and a 16bpp screen DC; race where the frame buffer is destroyed while a render goroutine still blits.","solutions":["Validate all eight coordinate/extent arguments are sensible (non-negative, non-zero where required) before the call.","Confirm both HDCs are alive at call time and that the source bitmap is still selected and not deleted.","For cross-format stretching, first convert via a compatible DC of the same color depth, or use SetStretchBltMode(COLORONCOLOR) before the call.","Capture GetLastError immediately on failure for the precise code.","Consider GDI+ (w32.GdipDrawImageRectRect) for high-quality scaling if format quirks persist."],"exampleFix":"// before\nw32.StretchBlt(hdcDst, 0, 0, -w, -h, hdcSrc, 0, 0, sw, sh, w32.SRCCOPY) // negative extents -> panic\n\n// after\nif w > 0 && h > 0 {\n\tw32.SetStretchBltMode(hdcDst, w32.COLORONCOLOR)\n\tw32.StretchBlt(hdcDst, 0, 0, w, h, hdcSrc, 0, 0, sw, sh, w32.SRCCOPY)\n}","handlingStrategy":"validation","validationCode":"func validStretchArgs(dw, dh, sw, sh int) bool {\n\treturn dw > 0 && dh > 0 && sw > 0 && sh > 0\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tif msg, _ := r.(string); strings.HasPrefix(msg, \"StretchBlt failed\") {\n\t\t\terr = fmt.Errorf(\"StretchBlt: %v (check DCs and extents)\", r)\n\t\t\treturn\n\t\t}\n\t\tpanic(r)\n\t}\n}()\nw32.StretchBlt(dst, 0, 0, dw, dh, src, 0, 0, sw, sh, w32.SRCCOPY)","preventionTips":["Validate all extents are positive before calling.","Confirm source bitmap/DC are alive at blit time (no deletion while rendering).","Set matching color depth or SetStretchBltMode before cross-format stretches."],"tags":["windows","gdi","imaging","syscall","panic"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}