babalae/better-genshin-impact · error · InvalidDataException

相对鼠标样本时间戳超出有效范围。

Error message

相对鼠标样本时间戳超出有效范围。

What it means

Thrown by ReadRelativeMouseBatch when the reconstructed timestamp (baseTicks + offsetMicroseconds * 10) overflows int64 (caught as OverflowException and re-wrapped), or when the result falls outside DateTime.MinValue.Ticks..DateTime.MaxValue.Ticks. Each sample stores a microsecond offset relative to the batch baseTicks; an absurd offset or corrupted baseTicks pushes the timestamp out of range.

Source

Thrown at BetterGenshinImpact/Service/Instance/InstanceIpcProtocol.cs:230

        var firstSequence = BinaryPrimitives.ReadUInt64LittleEndian(span[sizeof(ushort)..]);
        var baseTicks = BinaryPrimitives.ReadInt64LittleEndian(span[(sizeof(ushort) + sizeof(ulong))..]);
        var samples = new RelativeMouseSample[count];
        var offset = RelativeMouseBatchHeaderLength;
        for (var index = 0; index < count; index++)
        {
            var deltaX = BinaryPrimitives.ReadInt32LittleEndian(span[offset..]);
            var deltaY = BinaryPrimitives.ReadInt32LittleEndian(span[(offset + sizeof(int))..]);
            var offsetMicroseconds =
                BinaryPrimitives.ReadInt32LittleEndian(span[(offset + sizeof(int) * 2)..]);
            long timestampTicks;
            try
            {
                timestampTicks = checked(baseTicks + offsetMicroseconds * 10L);
            }
            catch (OverflowException exception)
            {
                throw new InvalidDataException("相对鼠标样本时间戳超出有效范围。", exception);
            }

            if (timestampTicks < DateTime.MinValue.Ticks
                || timestampTicks > DateTime.MaxValue.Ticks)
            {
                throw new InvalidDataException("相对鼠标样本时间戳超出有效范围。");
            }

            samples[index] = new RelativeMouseSample(
                deltaX,
                deltaY,
                new DateTime(timestampTicks, DateTimeKind.Utc));
            offset += RelativeMouseSampleLength;
        }

        return (firstSequence, samples);
    }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Restart both instances.
  2. Ensure both instances run the same build (timestamp encoding must match).
  3. If reproducing, log baseTicks and the offending offsetMicroseconds to identify whether it is corruption or an encoding mismatch.
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    var (firstSeq, samples) = InstanceIpcProtocol.ReadRelativeMouseBatch(frame.Value);
}
catch (InvalidDataException ex) when (ex.Message.Contains("时间戳超出有效范围"))
{
    logger.LogError(ex, "Mouse-sample timestamp out of range; corruption or encoding mismatch");
}

Prevention

When it happens

Trigger: Corrupt offsetMicroseconds (e.g. near int.MaxValue causing overflow when multiplied by 10), a corrupt baseTicks value, or a peer clock that produced timestamps outside the DateTime representable range.

Common situations: Stream/memory corruption flipping timestamp bytes; a peer bug writing offsets without the checked arithmetic the writer uses; version skew in the timestamp encoding.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/b965297858c00b7c. Report an issue: GitHub.