{"record":{"id":"5b1cba5b26979796","repo":"babalae/better-genshin-impact","slug":"error-5b1cba","errorCode":null,"errorMessage":"相对鼠标帧长度无效。","messagePattern":"相对鼠标帧长度无效。","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Instance/InstanceIpcProtocol.cs","lineNumber":210,"sourceCode":"    internal static (ulong FirstSequence, RelativeMouseSample[] Samples) ReadRelativeMouseBatch(\n        InstanceIpcFrame frame)\n    {\n        if (frame.PayloadType != InstanceIpcPayloadType.RelativeMouseBatch)\n        {\n            throw new InvalidDataException($\"预期相对鼠标帧，实际为 {frame.PayloadType}。\");\n        }\n\n        var span = frame.Payload.AsSpan();\n        if (span.Length < RelativeMouseBatchHeaderLength)\n        {\n            throw new InvalidDataException(\"相对鼠标帧头不完整。\");\n        }\n\n        var count = BinaryPrimitives.ReadUInt16LittleEndian(span);\n        if (count is 0 or > 64\n            || span.Length != RelativeMouseBatchHeaderLength + RelativeMouseSampleLength * count)\n        {\n            throw new InvalidDataException(\"相对鼠标帧长度无效。\");\n        }\n\n        var firstSequence = BinaryPrimitives.ReadUInt64LittleEndian(span[sizeof(ushort)..]);\n        var baseTicks = BinaryPrimitives.ReadInt64LittleEndian(span[(sizeof(ushort) + sizeof(ulong))..]);\n        var samples = new RelativeMouseSample[count];\n        var offset = RelativeMouseBatchHeaderLength;\n        for (var index = 0; index < count; index++)\n        {\n            var deltaX = BinaryPrimitives.ReadInt32LittleEndian(span[offset..]);\n            var deltaY = BinaryPrimitives.ReadInt32LittleEndian(span[(offset + sizeof(int))..]);\n            var offsetMicroseconds =\n                BinaryPrimitives.ReadInt32LittleEndian(span[(offset + sizeof(int) * 2)..]);\n            long timestampTicks;\n            try\n            {\n                timestampTicks = checked(baseTicks + offsetMicroseconds * 10L);\n            }\n            catch (OverflowException exception)","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Instance/InstanceIpcProtocol.cs#L192-L228","documentation":"Thrown by ReadRelativeMouseBatch when the decoded sample count is 0 or greater than 64, or when the payload length does not equal headerLength + count * sampleSize (12 bytes each). This catches both impossible counts and length/count mismatches that would cause out-of-bounds reads.","triggerScenarios":"The peer wrote count=0 (WriteRelativeMouseBatchAsync rejects this on the writer side, so this implies a non-standard peer), count>64, or a length that disagrees with the count — corruption or a protocol/version mismatch in the binary layout.","commonSituations":"Mixed-version instances with different sample layouts; stream corruption flipping count or length bytes; a peer implementation that bypasses the writer validation.","solutions":["Restart both instances.","Ensure both instances are the same build so the binary mouse-batch layout matches.","If reproducing, dump the raw header (count, declared length) to determine whether it is corruption or a layout mismatch."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var count = BinaryPrimitives.ReadUInt16LittleEndian(span);\nif (count is 0 or > 64\n    || span.Length != RelativeMouseBatchHeaderLength + RelativeMouseSampleLength * count)\n{\n    throw new InvalidDataException(\"相对鼠标帧长度无效。\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var (firstSeq, samples) = InstanceIpcProtocol.ReadRelativeMouseBatch(frame.Value);\n}\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"帧长度无效\"))\n{\n    logger.LogError(ex, \"Invalid mouse-batch length/count; restart instances\");\n}","preventionTips":["Run matching builds so the binary mouse-batch layout is identical.","Restart instances to recover from corruption.","If reproducing, dump the count and declared length to find the writer-side length bug."],"tags":["ipc","protocol","mouse","data-corruption","named-pipe"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}