EllanJiang/GameFramework · error · GameFrameworkException
Bytes is invalid.
Error message
Bytes is invalid.
What it means
DownloadAgentHelperUpdateBytesEventArgs.Create(bytes, offset, length) throws this when the bytes array is null. This event carries a chunk of downloaded stream data to append; there is no valid update without a buffer. (The source region also shows the related 'Offset is invalid.' guard for out-of-range offsets.)
Solutions
- Ensure the helper allocates its byte buffer before downloading and passes it to the update event.
- In the helper, skip the update callback (or raise the error callback) when the read produced no buffer.
- Validate bytes != null inside the helper before invoking the event.
Example fix
// before (custom IDownloadAgentHelper)
onUpdateBytes(this, DownloadAgentHelperUpdateBytesEventArgs.Create(buffer, 0, read)); // buffer may be null
// after
if (buffer != null)
onUpdateBytes(this, DownloadAgentHelperUpdateBytesEventArgs.Create(buffer, 0, read)); Defensive patterns
Strategy: type-guard
Validate before calling
if (bytes == null || offset < 0 || offset >= bytes.Length) raiseDownloadError();
Type guard
static bool IsValidChunk(byte[] b, int offset, int length) => b != null && offset >= 0 && offset < b.Length && length >= 0 && offset + length <= b.Length;
Try / catch
try { var e = DownloadAgentHelperUpdateBytesEventArgs.Create(bytes, offset, length); }
catch (GameFrameworkException) { Log.Error("Download helper produced an invalid byte chunk"); } Prevention
- Allocate the download buffer before starting the read loop
- Never invoke update events after a failed read; use the error event
- Range-check offset/length against the buffer in the helper
When it happens
Trigger: A custom IDownloadAgentHelper passing a null buffer to the update-bytes callback; a read operation that failed and still invoked the update event with null; uninitialized stream buffers in custom helpers.
Common situations: Implementing a custom download agent over a network stream where a failed Read returns null; reusing a buffer that was disposed/never allocated.
Related errors
- Length is invalid.
- Data table is invalid.
- Debugger window is invalid.
- Owner is invalid.
- Resource manager is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/a3010dae2ca59ea2.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Download/DownloadAgentHelperUpdateBytesEventArgs.cs:56
/// </summary>
public int Length
{
get;
private set;
}
/// <summary>
/// 创建下载代理辅助器更新数据流事件。
/// </summary>
/// <param name="bytes">下载的数据流。</param>
/// <param name="offset">数据流的偏移。</param>
/// <param name="length">数据流的长度。</param>
/// <returns>创建的下载代理辅助器更新数据流事件。</returns>
public static DownloadAgentHelperUpdateBytesEventArgs Create(byte[] bytes, int offset, int length)
{
if (bytes == null)
{
throw new GameFrameworkException("Bytes is invalid.");
}
if (offset < 0 || offset >= bytes.Length)
{
throw new GameFrameworkException("Offset is invalid.");
}
if (length <= 0 || offset + length > bytes.Length)
{
throw new GameFrameworkException("Length is invalid.");
}
DownloadAgentHelperUpdateBytesEventArgs downloadAgentHelperUpdateBytesEventArgs = ReferencePool.Acquire<DownloadAgentHelperUpdateBytesEventArgs>();
downloadAgentHelperUpdateBytesEventArgs.m_Bytes = bytes;
downloadAgentHelperUpdateBytesEventArgs.Offset = offset;
downloadAgentHelperUpdateBytesEventArgs.Length = length;
return downloadAgentHelperUpdateBytesEventArgs;
}View on GitHub (pinned to d0c010b051)