{"record":{"id":"f4b5d33e3e9a57c9","repo":"MathewSachin/Captura","slug":"failed-to-acquire-next-frame-acquireresult-resul","errorCode":null,"errorMessage":"Failed to acquire next frame: {acquireResult.Result.Code}","messagePattern":"Failed to acquire next frame: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Captura.Windows/DesktopDuplication/DuplCapture.cs","lineNumber":114,"sourceCode":"\n                var acquireResult = _frameGrabber.Grab();\n\n                if (acquireResult == null)\n                {\n                    // _device is being used by Desktop Duplication\n                    Texture.Device.ImmediateContext.CopySubresourceRegion(_bkpTexture,\n                        0,\n                        new ResourceRegion(0, 0, 0, _width, _height, 1),\n                        Texture,\n                        0,\n                        TargetPosition.X, TargetPosition.Y);\n\n                    return true;\n                }\n\n                if (acquireResult.Result.Failure)\n                {\n                    throw new Exception($\"Failed to acquire next frame: {acquireResult.Result.Code}\");\n                }\n\n                using (acquireResult.DesktopResource)\n                using (var tempTexture = acquireResult.DesktopResource.QueryInterface<Texture2D>())\n                {\n                    DxMousePointer?.Update(tempTexture, acquireResult.FrameInfo, _deskDupl);\n\n                    Texture.Device.ImmediateContext.CopySubresourceRegion(tempTexture,\n                        0,\n                        new ResourceRegion(0, 0, 0, _width, _height, 1),\n                        Texture,\n                        0,\n                        TargetPosition.X, TargetPosition.Y);\n\n                    _device.ImmediateContext.CopyResource(tempTexture, _bkpTexture);\n                }\n\n                _frameGrabber.Release();","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/MathewSachin/Captura/blob/3fdf41529bf4d50cd7a85aedd856f30e34279a47/src/Captura.Windows/DesktopDuplication/DuplCapture.cs#L96-L132","documentation":"Thrown by DuplCapture.Get (src/Captura.Windows/DesktopDuplication/DuplCapture.cs:114) when _frameGrabber.Grab() returns a result whose Result.Failure is true. AcquireNextFrame returned a failing DXGI code (e.g. access-lost, mode-change, device-removed, invalid-call) indicating the OutputDuplication is no longer valid and must be reinitialized.","triggerScenarios":"Grabbing the next desktop frame after the duplication was invalidated: display mode/resolution changed, monitor disconnected/reconnected, secure desktop (UAC) or lock screen shown, the duplication object became stale, or the D3D11 device was removed.","commonSituations":"User changed resolution/monitor config mid-capture; locked the screen or hit a UAC prompt; monitor went to sleep/disconnected; driver crash removed the device; multi-monitor topology changed.","solutions":["On access-lost / mode-change codes, call Init() to recreate _deskDupl and _frameGrabber, then resume.","Stop capture while the session is locked or on a secure desktop and resume after unlock.","Verify the monitor/output is still connected before re-attempting Grab.","Handle D3D11 device-removed by recreating the Device as well as the duplication."],"exampleFix":"// before\nif (acquireResult.Result.Failure)\n    throw new Exception($\"Failed to acquire next frame: {acquireResult.Result.Code}\");\n// after - reinitialize once on transient invalidation\nif (acquireResult.Result.Failure)\n{\n    if (acquireResult.Result.Code == ResultCode.AccessLost.Code) { Init(); return false; }\n    throw new Exception($\"Failed to acquire next frame: {acquireResult.Result.Code}\");\n}","handlingStrategy":"retry","validationCode":"// before Grab, sanity-check the output is still connected\nif (_deskDupl == null || _device == null) return false;","typeGuard":null,"tryCatchPattern":"try { capture.Get(texture, pointer, pos); }\ncatch (Exception e) when (e.Message.Contains(\"Failed to acquire next frame\")) { capture.Init(); /* reinitialize once, then resume */ }","preventionTips":["Recreate the duplication (Init) on access-lost / mode-change codes.","Pause capture while the session is locked or on a secure desktop.","Handle D3D11 device-removed by rebuilding the Device, not just the duplication."],"tags":["desktop-duplication","dxgi","sharpdx","frame-acquisition","windows","csharp"],"backgroundTag":null,"analyzedSha":"3fdf41529bf4d50cd7a85aedd856f30e34279a47","analyzedAt":"2026-08-13T19:35:27.486Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}