Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve biome setting to avoid writing directly to chunk #2757

Merged
merged 2 commits into from
Jun 15, 2024

Conversation

dordsor21
Copy link
Member

@dordsor21 dordsor21 commented Jun 2, 2024

  • Removes possibility of writing to the LevelChunkSection biomes PalettedContainer whilst it is being read from the main thread

 - Removes possibility of writing to the LevelChunkSection biomes PalettedContainer whilst it is being read for sending packets
 - I believe this occured mostly on clipboard operations where blocks are written before biomes, so chunks are being sent whilst writing biomes
 - This would explain why the error reported in the below issue (and others) is/was so rare
 - Of course I could be completely wrong about all of this, but given the line in LevelChunkSection#write that the error seems to consistently occur on is when writing biomes to the packet, and that the only place I can find in FAWE where we write to a "live" PalettedContainer is for biomes, I am reasonably confident that this is the cause
 - Should address #2729
@dordsor21 dordsor21 requested a review from a team as a code owner June 2, 2024 16:17
@github-actions github-actions bot added the Bugfix This PR fixes a bug label Jun 2, 2024
@SirYwell
Copy link
Member

SirYwell commented Jun 8, 2024

From my understanding, the linked issue is caused by the fact that we manipulate the LevelChunk object. The ClientboundLevelChunkPacketData writes a chunk in two steps:

  1. Calculate a byte array, with a size calculated by calculateChunkSize(LevelChunk)
    • calls getSections() and calls LevelChunkSection#getSerializedSize() on each of the sections
  2. With this byte array, it now calls extractChunkData, and passes the chunk again
    • calls getSections() again and calls LevelChunkSection#write(...) on each of the sections

So if we change anything about the LevelChunk object in between those two steps (i.e. modifying the sections array, or replacing the biomes palette of a LevelChunkSection (solution proposed here), or writing to a biomes palette (current solution)) we might get a mismatch between the calculated size and the actual size it tries to write.

Am I missing something?

@dordsor21
Copy link
Member Author

Ah yeah that does make more sense. The changes here are ones that should probably go in anyway so I'll edit the PR desc

@dordsor21 dordsor21 requested a review from a team June 9, 2024 07:25
Comment on lines 141 to 148
Field tmpFieldBiomes;
try {
// It seems to actually be biomes, but is apparently obfuscated to "j"
tmpFieldBiomes = LevelChunkSection.class.getDeclaredField("biomes");
} catch (NoSuchFieldException ignored) {
tmpFieldBiomes = LevelChunkSection.class.getDeclaredField("j");
}
fieldBiomes = tmpFieldBiomes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops one more question, why isn't this using Refraction like the other fields?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// It seems to actually be biomes, but is apparently obfuscated to "j"

MiniMappingViewer said j but when actually using it, it was biomes for whatever reason

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you tested that on paper, you probably encountered the remapped version - but paper should also successfully remap j to biomes then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but got fieldNotFound exception so idk what was up. Didn't bother to look into it further than this fixed it tbh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me on 1.20.6

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was on 1.20.4, I also didn't bother checking every version, just assumed it could be an issue there as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also works on 1.20.4 for me, Refraction properly detects that it's running in a mojmapped environment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll stick it back to normal and assume it was something off just once

@dordsor21 dordsor21 requested a review from a team June 9, 2024 12:26
@NotMyFault NotMyFault merged commit af83b2f into main Jun 15, 2024
11 checks passed
@NotMyFault NotMyFault deleted the fix/improved-biome-setting branch June 15, 2024 11:08
dordsor21 referenced this pull request Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix This PR fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants