EllanJiang/GameFramework · error · GameFrameworkException

Result is invalid.

Error message

Result is invalid.

What it means

Utility.Verifier.GetCrc32Bytes(int crc32, byte[] bytes, int offset) writes the 4-byte big-endian representation of a CRC32 into a caller-supplied array. It throws GameFrameworkException("Result is invalid.") when the target byte array is null, guarding before the writes occur.

Solutions

  1. Allocate the result array (at least offset + 4 bytes) before calling
  2. Null-check the result buffer at the call site
  3. Catch GameFrameworkException to report buffer-preparation failures

Example fix

// before
Utility.Verifier.GetCrc32Bytes(crc, result, 0); // result null
// after
byte[] result = new byte[4];
Utility.Verifier.GetCrc32Bytes(crc, result, 0);
Defensive patterns

Strategy: validation

Validate before calling

if (result == null || result.Length < offset + 4) throw new InvalidOperationException("result buffer too small");

Type guard

static bool CanHoldCrc(byte[] bytes, int offset) => bytes != null && offset >= 0 && offset + 4 <= bytes.Length;

Try / catch

try { Utility.Verifier.GetCrc32Bytes(crc, result, 0); }
catch (GameFrameworkException ex) { Log.Warning("CRC write failed: {0}", ex.Message); }

Prevention

When it happens

Trigger: Calling GetCrc32Bytes(crc32, result, offset) with result == null — e.g. the output buffer was never allocated or an earlier allocation failed and null propagated.

Common situations: Preparing version/checksum bytes for a package manifest where the result buffer comes from a pooled allocator that returned null; refactored code that dropped the buffer allocation.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/b19d0549c2247800. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Utility/Utility.Verifier.cs:125

            /// </summary>
            /// <param name="crc32">CRC32 数值。</param>
            /// <param name="bytes">要存放结果的数组。</param>
            public static void GetCrc32Bytes(int crc32, byte[] bytes)
            {
                GetCrc32Bytes(crc32, bytes, 0);
            }

            /// <summary>
            /// 获取 CRC32 数值的二进制数组。
            /// </summary>
            /// <param name="crc32">CRC32 数值。</param>
            /// <param name="bytes">要存放结果的数组。</param>
            /// <param name="offset">CRC32 数值的二进制数组在结果数组内的起始位置。</param>
            public static void GetCrc32Bytes(int crc32, byte[] bytes, int offset)
            {
                if (bytes == null)
                {
                    throw new GameFrameworkException("Result is invalid.");
                }

                if (offset < 0 || offset + 4 > bytes.Length)
                {
                    throw new GameFrameworkException("Offset or length is invalid.");
                }

                bytes[offset] = (byte)((crc32 >> 24) & 0xff);
                bytes[offset + 1] = (byte)((crc32 >> 16) & 0xff);
                bytes[offset + 2] = (byte)((crc32 >> 8) & 0xff);
                bytes[offset + 3] = (byte)(crc32 & 0xff);
            }

            internal static int GetCrc32(Stream stream, byte[] code, int length)
            {
                if (stream == null)
                {
                    throw new GameFrameworkException("Stream is invalid.");

View on GitHub (pinned to d0c010b051)