EllanJiang/GameFramework · error · GameFrameworkException
Max block count is invalid.
Error message
Max block count is invalid.
What it means
FileSystem.Create requires maxBlockCount to be positive because the filesystem stores data in fixed-size blocks and the header must reserve at least one. Non-positive values make the archive layout invalid, so Create throws.
Solutions
- Pass a positive maxBlockCount (must also be >= maxFileCount)
- Validate any config-derived value before calling Create
- Check parameter order in the Create call — maxFileCount comes before maxBlockCount
- Size blocks based on expected data volume, leaving growth headroom
Example fix
// before var fs = FileSystem.Create(path, access, stream, files, 0); // after int maxBlockCount = Math.Max(files, 64); var fs = FileSystem.Create(path, access, stream, files, maxBlockCount);
Defensive patterns
Strategy: validation
Validate before calling
if (maxBlockCount <= 0) throw new ArgumentOutOfRangeException(nameof(maxBlockCount), maxBlockCount, "must be positive"); FileSystem.Create(fullPath, access, stream, maxFileCount, maxBlockCount);
Type guard
bool IsValidMaxBlockCount(int n) => n > 0;
Try / catch
try { var fs = FileSystem.Create(path, access, stream, fc, bc); }
catch (GameFrameworkException ex) when (ex.Message == "Max block count is invalid.") { Log.Error($"maxBlockCount={bc} — check config source"); } Prevention
- Validate config-driven capacity values at load time
- Ensure the block count is derived from actual data-size needs, not left at a zero default
- Keep parameter order (maxFileCount, maxBlockCount) straight
When it happens
Trigger: Calling FileSystem.Create with maxBlockCount <= 0, commonly from a missing or zero-defaulting config value, or a mis-ordered argument list.
Common situations: Settings object where MaxBlocks was never set; computed block count from a formula that returned zero for empty input; swapping maxFileCount and maxBlockCount arguments by mistake.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Offset is invalid.
- Length is invalid.
- Max file count is invalid.
- Name is invalid.
- Stream is not writable.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/8bd6c823c180ad22.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/FileSystem/FileSystem.cs:148
/// <summary>
/// 创建文件系统。
/// </summary>
/// <param name="fullPath">要创建的文件系统的完整路径。</param>
/// <param name="access">要创建的文件系统的访问方式。</param>
/// <param name="stream">要创建的文件系统的文件系统流。</param>
/// <param name="maxFileCount">要创建的文件系统的最大文件数量。</param>
/// <param name="maxBlockCount">要创建的文件系统的最大块数据数量。</param>
/// <returns>创建的文件系统。</returns>
public static FileSystem Create(string fullPath, FileSystemAccess access, FileSystemStream stream, int maxFileCount, int maxBlockCount)
{
if (maxFileCount <= 0)
{
throw new GameFrameworkException("Max file count is invalid.");
}
if (maxBlockCount <= 0)
{
throw new GameFrameworkException("Max block count is invalid.");
}
if (maxFileCount > maxBlockCount)
{
throw new GameFrameworkException("Max file count can not larger than max block count.");
}
FileSystem fileSystem = new FileSystem(fullPath, access, stream);
fileSystem.m_HeaderData = new HeaderData(maxFileCount, maxBlockCount);
CalcOffsets(fileSystem);
Utility.Marshal.StructureToBytes(fileSystem.m_HeaderData, HeaderDataSize, s_CachedBytes);
try
{
stream.Write(s_CachedBytes, 0, HeaderDataSize);
stream.SetLength(fileSystem.m_FileDataOffset);
return fileSystem;
}View on GitHub (pinned to d0c010b051)