wailsapp/wails · error

SelectObject failed

Error message

SelectObject failed

What it means

Error "SelectObject failed" thrown in wailsapp/wails.

Source

Thrown at v3/pkg/w32/gdi32.go:374

	return ret != 0
}

func ResetDC(hdc HDC, lpInitData *DEVMODE) HDC {
	ret, _, _ := procResetDC.Call(
		uintptr(hdc),
		uintptr(unsafe.Pointer(lpInitData)))

	return HDC(ret)
}

func SelectObject(hdc HDC, hgdiobj HGDIOBJ) HGDIOBJ {
	ret, _, _ := procSelectObject.Call(
		uintptr(hdc),
		uintptr(hgdiobj))

	if ret == 0 {
		panic("SelectObject failed")
	}

	return HGDIOBJ(ret)
}

func SetBkMode(hdc HDC, iBkMode int) int {
	ret, _, _ := procSetBkMode.Call(
		uintptr(hdc),
		uintptr(iBkMode))

	if ret == 0 {
		panic("SetBkMode failed")
	}

	return int(ret)
}

func SetBrushOrgEx(hdc HDC, nXOrg, nYOrg int, lppt *POINT) bool {

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Ensure the HGDIOBJ being selected is valid and not already deleted; selecting a deleted brush, pen, or bitmap makes SelectObject fail.
  2. Do not select a bitmap into more than one DC at a time; deselect it from the previous DC first.
  3. Do not select a stock object that is still selected into another DC in an incompatible way; restore the original object returned by the first SelectObject call before deleting objects.

When it happens

Trigger: Occurs when SelectObject returns NULL or HGDI_ERROR, e.g. selecting a deleted GDI object, a bitmap into incompatible DCs simultaneously, or an invalid DC handle.

Common situations: See trigger scenarios.


AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15). Data as JSON: /api/errors/b39367d1c720f111. Report an issue: GitHub.