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

Block cache corruption when modifying results of getBlock() #2770

Open
dktapps opened this issue Feb 17, 2019 · 1 comment
Open

Block cache corruption when modifying results of getBlock() #2770

dktapps opened this issue Feb 17, 2019 · 1 comment
Labels
Category: API Related to the plugin API Category: Core Related to internal functionality Status: Debugged Cause of the bug has been found, but not fixed

Comments

@dktapps
Copy link
Member

dktapps commented Feb 17, 2019

Issue description

Blocks are cached at the world level to improve performance of accesses. This is problematic because getBlock() does not clone or remove blocks from the cache, so if they are modified without setting them back into the world, the block cache becomes corrupted.

This has been seen in the past when plugin devs modify the meta values of things like wool expecting to see a different colour - it sort-of works if you click on it totrigger block updates, but the changes don't save.

  • Expected result: Modifying the result of getBlock() should have no effect on the world or its block cache
  • Actual result: What actually happened? Cache becomes polluted with modifications that haven't been written to the world.

Steps to reproduce the issue

  1. Fetch a block from the world, such as wool.
  2. Alter its properties in some way, for example changing its meta value.
  3. Don't setBlock().
  4. Click the block in game and notice the block appears to have updated to reflect your change.
  5. Quit the game and rejoin and notice nothing is there.

OS and versions

@dktapps dktapps added Category: API Related to the plugin API Category: Core Related to internal functionality Status: Debugged Cause of the bug has been found, but not fixed labels Feb 17, 2019
@dktapps
Copy link
Member Author

dktapps commented Oct 30, 2021

This could be solved by implementing a BlockCacheRecord which records the fullID of the block, alongside the block object that's supposed to represent it. If the block object's fullID doesn't match the recorded ID, we throw it away and get a new one from BlockFactory. However, this would come at a minor performance cost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: API Related to the plugin API Category: Core Related to internal functionality Status: Debugged Cause of the bug has been found, but not fixed
Projects
None yet
Development

No branches or pull requests

1 participant