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

Unsafety in sort of important variable in CraftBlockStates #293

Open
PedroMPagani opened this issue Sep 19, 2024 · 0 comments
Open

Unsafety in sort of important variable in CraftBlockStates #293

PedroMPagani opened this issue Sep 19, 2024 · 0 comments
Labels
status: needs triage type: bug Something doesn't work as it was intended to.

Comments

@PedroMPagani
Copy link

PedroMPagani commented Sep 19, 2024

Expected behavior

The variable DISABLE_SNAPSHOT is kept as a static boolean on paper, but since paper is ticking single threaded, it doesn't really run into issues, every Folia call however, does not take this into consideration,
I think this should be changed to
ThreadLocal, otherwise this could possibly lead into issues?

# public static boolean DISABLE_SNAPSHOT = false; << PAPER.

public static final ThreadLocal<Boolean> DISABLE_SNAPSHOT = ThreadLocal.withInitial(() -> false);

        this.snapshotDisabled = DISABLE_SNAPSHOT.get();
        if (snapshotDisabled) {
            this.snapshot = this.tileEntity;
        } else {
            this.snapshot = this.createSnapshot(tileEntity);
        }
        
        
                boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
        CraftBlockEntityState.DISABLE_SNAPSHOT.set(!useSnapshot);
        try {
        // Paper end
        CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockPosition, blockData, tileEntity);
        blockState.setWorldHandle(craftBlock.getHandle()); // Inject the block's generator access
        return blockState;
        // Paper start
        } finally {
            CraftBlockEntityState.DISABLE_SNAPSHOT.set(prev);
        }

Observed/Actual behavior

Steps/models to reproduce

Plugin and Datapack List

Folia version

Other

@PedroMPagani PedroMPagani added status: needs triage type: bug Something doesn't work as it was intended to. labels Sep 19, 2024
@PedroMPagani PedroMPagani changed the title Unsafety in sort of important variable Unsafety in sort of important variable in CraftBlockStates Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage type: bug Something doesn't work as it was intended to.
Projects
None yet
Development

No branches or pull requests

1 participant