papyrus-mc / papyruscs

PapyrusCS renders maps of Minecraft: Bedrock Edition worlds using C#, LevelDB and leaflet.
Apache License 2.0
255 stars 42 forks source link

Given NBT stream does not start with a TAG_Compound #91

Open ryanjanke opened 2 years ago

ryanjanke commented 2 years ago

Has anyone else seen this issue with backup downloaded from a realm?

8188 of 47821 Chunks render @ 244.8 cps Error in CreateChunkAndRenderBlock: Given NBT stream does not start with a TAG_Compound

When I download from a Bedrock Realm running 1.17.34 I see this about 20 times, then there are chunks in the map that show as black. Usually it's ones where there is a lot of player constructed objects at multiple Y levels.

wraithgar commented 2 years ago

Probably related, I'm seeing odd version 9 subchunks as of 1.17.34 (using the official bedrock server) that have what appears to be an empty runtime/palette byte.

Manually parsing the data it appears to be where the paletteAndFlag usually are, there are two empty bytes followed by a single nbt.

I made a gist trying to show the data I have, compared to a valid subchunk that's at the very next subchunk_index https://gist.github.com/wraithgar/a01b99ee7433a9c8a359069952f2147e

evilzenscientist commented 2 years ago

+1 with newest Bedrock - I don't this is specifically realm related, perhaps a change in data structure for all bedrock maps?

TapeWerm commented 2 years ago

I use bedrock dedicated server and see this. I should poke my world and find what NBT is causing this. Edit: The chunks have barrels in common, I have not poked my save data which is a bit big to upload to GitHub.

quaderror commented 2 years ago

+1 for the newest Bedrock, and I'm not using a realm. Ran into this after freshly cloning and compiling with the instructions for linux-x64.

ryanjanke commented 2 years ago

My own testing seems to corroborate @TapeWerm's observation that all the affected chunks contain barrels.

TapeWerm commented 2 years ago

I should emphasize it could be a complete coincidence, there are chunks that also have barrels that rendered just fine. Amulet Editor loaded the chunks Papyrus CS failed to, and I haven't read my world's leveldb files.

TapeWerm commented 2 years ago

Probably related, I'm seeing odd version 9 subchunks as of 1.17.34 (using the official bedrock server) that have what appears to be an empty runtime/palette byte.

Manually parsing the data it appears to be where the paletteAndFlag usually are, there are two empty bytes followed by a single nbt.

I made a gist trying to show the data I have, compared to a valid subchunk that's at the very next subchunk_index https://gist.github.com/wraithgar/a01b99ee7433a9c8a359069952f2147e

If I wrap a if (paletteAndFlag != 0) around

for (int palletId = 0; palletId < localPalette.Size; palletId++)
{
    var (name, val) = GetNbtVal(ms);
    localPalette.Put(palletId, name, val);
}

in https://github.com/papyrus-mc/papyruscs/blob/master/Maploader/World/World.cs the map comes out fine. Heavy emphasis on I am not remotely familiar with the codebase, I would be shocked if that is a proper fix without introducing regressions.

Edit: Adding a basecase to continue before that for loop also works and seems more efficient, but as always remember that I do not know what I am doing. localPalette.Size is almost the max int value on storage 1 for some version 9 chunks. I suspect the Size is not actually reading an int but a string or some other value.

if (paletteAndFlag == 0)
    continue;
for (int palletId = 0; palletId < localPalette.Size; palletId++)
{
    var (name, val) = GetNbtVal(ms);
    localPalette.Put(palletId, name, val);
}

Edit 2: Might be safer to just return than continue to the next loop iteration given the file reader.