{"record":{"id":"f35d039de0f02898","repo":"gravitational/teleport","slug":"failed-to-resize-crop-region","errorCode":null,"errorMessage":"failed to resize crop region","messagePattern":"failed to resize crop region","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/srv/desktop/rdp/decoder/decoder.go","lineNumber":201,"sourceCode":"\tvar withCursorC C.uint8_t\n\tif withCursor {\n\t\twithCursorC = 1\n\t}\n\n\tok := C.rdp_decoder_resize_crop(\n\t\td.ptr,\n\t\tC.uint16_t(cropX),\n\t\tC.uint16_t(cropY),\n\t\tC.uint16_t(cropW),\n\t\tC.uint16_t(cropH),\n\t\tC.uint16_t(outWidth),\n\t\tC.uint16_t(outHeight),\n\t\t(*C.uint8_t)(unsafe.SliceData(buf)),\n\t\tC.size_t(len(buf)),\n\t\twithCursorC,\n\t)\n\tif !bool(ok) {\n\t\treturn nil, errors.New(\"failed to resize crop region\")\n\t}\n\n\treturn &image.RGBA{\n\t\tPix:    buf,\n\t\tStride: w * bpp,\n\t\tRect:   image.Rect(0, 0, w, h),\n\t}, nil\n}\n\n// SetCursorPosition overrides the decoder's tracked cursor position. Useful for cursor updates that arrive outside of\n// the RDP fast-path stream (e.g., TDPB MouseMove events). Does not change visibility — visibility is still driven by\n// RDP fast-path pointer updates.\nfunc (d *Decoder) SetCursorPosition(x, y uint16) {\n\tif d == nil || d.ptr == nil {\n\t\treturn\n\t}\n\n\tC.rdp_decoder_set_cursor_position(d.ptr, C.uint16_t(x), C.uint16_t(y))","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/gravitational/teleport/blob/1283425b60ec5f60d509ba4c791183d452923ff7/lib/srv/desktop/rdp/decoder/decoder.go#L183-L219","documentation":"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.","triggerScenarios":"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.","commonSituations":"Requesting extreme or odd crop dimensions; decoder hit an internal error earlier; native RDP graphics pipeline reset mid-stream; unsupported scale factor.","solutions":["Check the native/C-side logs for the concrete resize failure reason","Validate outWidth/outHeight/cropW/cropH are sane, non-zero and within the source frame bounds before calling","Retry after the decoder processes a fresh frame (transient pipeline state)","If persistent, recreate the decoder connection"],"exampleFix":"// before\nimg, err := dec.ResizeCrop(0, 0, 999999, 999999, 1)\n// after\nw := min(outW, srcW); h := min(outH, srcH)\nimg, err := dec.ResizeCrop(0, 0, w, h, 1)","handlingStrategy":"validation","validationCode":"if outWidth == 0 || outHeight == 0 || cropW == 0 || cropH == 0 || cropX+cropW > srcW || cropY+cropH > srcH {\n    return nil, errors.New(\"invalid crop/resize dimensions\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp crop dimensions to source frame bounds","Check decoder health before resizing","Log native failures for diagnosis"],"tags":["rdp","desktop","cgo","video-decoding"],"backgroundTag":"native-resize-failure","analyzedSha":"1283425b60ec5f60d509ba4c791183d452923ff7","analyzedAt":"2026-09-02T04:06:41.601Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}