gravitational/teleport · error

failed to resize crop region

Error message

failed to resize crop region

What it means

The CGO call that performs the actual crop/resize (into a preallocated buffer) returned false, meaning the native resize routine failed. The Go wrapper discards the buffer and surfaces a generic error.

Source

Thrown at lib/srv/desktop/rdp/decoder/decoder.go:201

	var withCursorC C.uint8_t
	if withCursor {
		withCursorC = 1
	}

	ok := C.rdp_decoder_resize_crop(
		d.ptr,
		C.uint16_t(cropX),
		C.uint16_t(cropY),
		C.uint16_t(cropW),
		C.uint16_t(cropH),
		C.uint16_t(outWidth),
		C.uint16_t(outHeight),
		(*C.uint8_t)(unsafe.SliceData(buf)),
		C.size_t(len(buf)),
		withCursorC,
	)
	if !bool(ok) {
		return nil, errors.New("failed to resize crop region")
	}

	return &image.RGBA{
		Pix:    buf,
		Stride: w * bpp,
		Rect:   image.Rect(0, 0, w, h),
	}, nil
}

// SetCursorPosition overrides the decoder's tracked cursor position. Useful for cursor updates that arrive outside of
// the RDP fast-path stream (e.g., TDPB MouseMove events). Does not change visibility — visibility is still driven by
// RDP fast-path pointer updates.
func (d *Decoder) SetCursorPosition(x, y uint16) {
	if d == nil || d.ptr == nil {
		return
	}

	C.rdp_decoder_set_cursor_position(d.ptr, C.uint16_t(x), C.uint16_t(y))

View on GitHub (pinned to 1283425b60)

Solutions

  1. Check the native/C-side logs for the concrete resize failure reason
  2. Validate outWidth/outHeight/cropW/cropH are sane, non-zero and within the source frame bounds before calling
  3. Retry after the decoder processes a fresh frame (transient pipeline state)
  4. If persistent, recreate the decoder connection

Example fix

// before
img, err := dec.ResizeCrop(0, 0, 999999, 999999, 1)
// after
w := min(outW, srcW); h := min(outH, srcH)
img, err := dec.ResizeCrop(0, 0, w, h, 1)
Defensive patterns

Strategy: validation

Validate before calling

if outWidth == 0 || outHeight == 0 || cropW == 0 || cropH == 0 || cropX+cropW > srcW || cropY+cropH > srcH {
    return nil, errors.New("invalid crop/resize dimensions")
}

Prevention

When it happens

Trigger: Calling ResizeCrop where the native rdp_decoder resize/crop routine returns failure — e.g. incompatible source/target dimensions, decoder in a bad state, or the native call cannot honor the requested crop region.

Common situations: Requesting extreme or odd crop dimensions; decoder hit an internal error earlier; native RDP graphics pipeline reset mid-stream; unsupported scale factor.

Related errors


AI-assisted analysis of gravitational/teleport@1283425b60 (2026-09-02). Data as JSON: /api/errors/f35d039de0f02898. Report an issue: GitHub.