ZenKit: mod world with a too short mesh chunk length hangs loading - Renovation 2026 DRAGONISLAND.ZEN
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
The workaround was in ZenWorldArchiveFixDomain.TryFixMeshChunkLengths and ResourceCacheService.LoadWorld; the proposed upstream changes are in ZenKit's World.cc, Mesh.cc, and proto::read_chunked. Start by testing the patched ZenKit with the real DRAGONISLAND.ZEN, then check other mods and rebuild libzenkitcapi for Windows, Quest, and Pico. Done means the world loads in Gothic-Unity and the results are ready for the ZenKit issue and pull request.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
Renovation 2026 (Gothic 2 mod) world DRAGONISLAND.ZEN makes ZenKit hang (no exception) - the game freezes in PreCaching. The original engine loads it fine.
Cause (ZenKit)
The world mesh's material chunk (0xB020) stores a too small length: 75890 instead of 76067 bytes, its last material is left out. The engine reads the materials one by one and doesn't notice. ZenKit:
- Hangs in
World.cc: it hops over the mesh chunks by their stated sizes (do { id; seek(len) } while (id != 0xB060)) to read the BSP tree first. With the wrong size it lands inside the last material, walks garbage sizes to EOF, and loops there forever (seeking past the end of an in-memory stream is a no-op,read_ushort()at EOF returns 0, so 0xB060 is never found). - Loses data:
proto::read_chunkedseeks back to the stated chunk end after the material handler correctly read past it, and reads the rest of the last material as further chunks (vertices/polygons lost orbad_alloc).
Workaround we had (removed again, branch split/23-world)
ZenWorldArchiveFixDomain.TryFixMeshChunkLengths: for every world while a mod was active, ResourceCacheService.LoadWorld copied the world file, walked the ASCII [MeshAndBsp entry's chunk chain (0xB0../0xC0..) and, when a chunk wasn't followed by a known chunk, set its length up to the next spot (within 1 MB) from which the chain continues up to 0xC0FF. Only ASCII archives (binary ones store the entry differently).
Cost to remember for any future workaround: Vfs.Find(name).Buffer.Bytes copies the whole .zen into a managed byte[] (tens of MB for a big world) on every world load while a mod is active - even when nothing needs fixing; the copy was discarded and ZenKit read the VFS again → GC spike on Quest. If a workaround comes back, limit it to worlds shipped by the mod itself and avoid the copy when the chain is fine.
Workaround code
/// <summary>
/// Chunk length: a chunk of the world mesh whose stored length is wrong - ZenKit jumps
/// to the wrong spot, reads the data there as the next chunk and hangs (no exception: the game froze in
/// PreCaching). Renovation 2026's DRAGONISLAND.ZEN: the materials chunk's length leaves out its last material
/// (75890 instead of 76067). The engine reads the materials one by one and doesn't notice.
/// The chunks are walked; a chunk not followed by a known chunk gets the length up to the next spot from which
/// the chain continues. Returns the fixed copy or null when the chain is fine (or the world isn't an ASCII
/// archive - the binary ones store the entry differently).
/// </summary>
public static byte[] TryFixMeshChunkLengths(byte[] data, out string reason)
{
// BIN_SAFE worlds (vanilla) have "[MeshAndBsp" as a string too, but not the raw chunks right after it.
var tag = IndexOf(data, _asciiFormatTag, 0, Math.Min(data.Length, 256)) < 0
? -1
: IndexOf(data, _meshAndBspTag, 0, Math.Min(data.Length, 4096));
if (tag < 0)
{
reason = "no ASCII [MeshAndBsp] entry";
return null;
}
// The entry's stored size can be wrong as well (DRAGONISLAND.ZEN: short by the same material) - ZenKit
// doesn't use it, the chunks are walked up to the BSP's end chunk within the file.
var blob = Array.IndexOf(data, (byte)'\n', tag) + 1;
var end = data.Length;
byte[] fixedData = null;
var fixes = new List<string>();
var chunk = blob + 8;
while (chunk + 6 <= end)
{
var source = fixedData ?? data;
var id = BitConverter.ToUInt16(source, chunk);
if (id == _bspEndChunk)
break;
var length = BitConverter.ToInt32(source, chunk + 2);
var next = chunk + 6L + length;
if (length >= 0 && next + 6 <= end &&
_meshAndBspChunks.Contains(BitConverter.ToUInt16(source, (int)next)))
{
chunk = (int)next;
continue;
}
var realNext = FindChunkChain(source, (int)Math.Min(end, chunk + 6L + Math.Max(0, length)), end);
if (realNext < 0)
{
reason = $"chunk 0x{id:X4} at {chunk}: stored length {length} leads nowhere, no chunk found " +
"behind it";
return null;
}
fixedData ??= (byte[])data.Clone();
var realLength = realNext - chunk - 6;
BitConverter.GetBytes(realLength).CopyTo(fixedData, chunk + 2);
fixes.Add($"chunk 0x{id:X4} length {length} -> {realLength}");
chunk = realNext;
}
reason = fixedData == null ? "chunk lengths are fine" : string.Join(", ", fixes);
return fixedData;
}
private static bool IsChunkChain(byte[] data, int position, int end)
{
if (position < 0 || position + 6 > end ||
!_meshAndBspChunks.Contains(BitConverter.ToUInt16(data, position)))
return false;
if (BitConverter.ToUInt16(data, position) == _bspEndChunk)
return true;
// long: a garbage length mustn't overflow into a valid looking position.
var next = position + 6L + BitConverter.ToInt32(data, position + 2);
return next >= position + 6 && next + 6 <= end &&
_meshAndBspChunks.Contains(BitConverter.ToUInt16(data, (int)next));
}
private static int FindChunkChain(byte[] data, int start, int end)
{
var searchEnd = Math.Min(end - 6, start + _maxChunkLengthError);
for (var i = start; i <= searchEnd; i++)
{
if (data[i + 1] is 0xB0 or 0xC0 && IsChunkChain(data, i, end))
return i;
}
return -1;
}
Proposed upstream fix (prepared locally in ZenKit, not submitted yet)
World.cc: read the world mesh sequentially (mesh → BSP → triangulate) like the engine, the chunk hopping loop is gone.Mesh.cc(MATERIAL chunk): if the materials alone run past the stated chunk end, the size is wrong - continue after the materials (+ G2alpha_testbyte) and log an error. Not a global "never seek back": ZenKit's ownMesh::savedoesn't write the G2alpha_testbyte, its round trip relies on seeking back.proto::read_chunked: a chunk whose stated end lies past the input ends the loop with an error instead of hanging; fixes the underflowing overflow log value.- Tests:
read_chunkededge cases and a world round trip with a shortened material chunk (fail on current ZenKit, pass with the fix). All 23 vanilla G1/G2/Addon worlds load with identical counts before and after. - Not covered: another mesh/BSP chunk with a wrong size (garbage, but no hang); a material chunk short by only the 1-byte
alpha_testflag.
Suggested commit: fix(World): read the world mesh sequentially and stop on chunks reaching past the input
Side notes for upstream: Mesh::save doesn't write the G2 alpha_test byte; BspTree::load crashes on an empty BSP tree.
Before we go to the ZenKit author
- Test the patched ZenKit with the real
DRAGONISLAND.ZEN(Renovation 2026) - not done yet, the file wasn't available - Check other mods for other wrong chunk sizes (not covered by the fix)
- Rebuild
libzenkitcapi(Windows, Quest, Pico) with the fix and load the world in Gothic-Unity - Open the ZenKit issue + PR with the results (GothicKit/ZenKit)
- Ngôn ngữ chính
- C#
- Star
- 33
- Fork
- 1
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 76
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Gothic-Unity-Project/Gothic-Unity
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Gothic-Unity-Project/Gothic-Unity#533 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 53/100
Gothic-Unity-Project/Gothic-Unity#523 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
improvement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
Gothic-Unity-Project/Gothic-Unity#521 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Gothic-Unity-Project/Gothic-Unity#504 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Gothic-Unity-Project/Gothic-Unity#501 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Gothic-Unity-Project/Gothic-Unity
Issue tương tự
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
openclaw/openclaw-windows-node#2287 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:host area:operations type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
kind:ux needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
elsa-workflows/elsa-foundation#4742 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
[LANG] Add support for C# (.cs)Đang mởenhancement good first issue help wanted new-language
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100