Skip to content

Fix BlockIterator callback lifecycle issue. - #6794

Merged
Big-Iron-Cheems merged 6 commits into
MeteorDevelopment:masterfrom
maartix1:new-pr-work
Nov 11, 2026
Merged

Big-Iron-Cheems merged 6 commits into
MeteorDevelopment:masterfrom
maartix1:new-pr-work

Conversation

@maartix1

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix
  • New feature

Description

This PR improves callback handling in BlockIterator to prevent unnecessary block scanning and ensure reliable callback cleanup.

Related issues

Im not find any.

How Has This Been Tested?

BUILD SUCCESSFUL in 40s
Game starts without errors

Checklist:

  • My code follows the style guidelines of this project.
  • I have added comments to my code in more complex areas.
  • I have tested the code in both development and production environments.

@maartix1

Copy link
Copy Markdown
Contributor Author

Hi, can someone reviev my code?

hRadius = Math.max(hRadius, horizontalRadius);
vRadius = Math.max(vRadius, verticalRadius);

if (processing) pendingCallbacks.add(callback);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

module logic is inherently synchronous, and a cross-thread write to ReferenceArrayList can end up throwing a ConcurrentModificationException
if anything this should be

if (processing) throw new IllegalStateException();

but i think keeping the method as it was previously is fine as modules being synchronous goes without saying

Comment on lines 104 to 108
try {
callback.run();
} catch (RuntimeException e) {
MeteorClient.LOG.error("Error while executing a BlockIterator after callback.", e);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

never try/catch arbitrary module code, failing-fast is important for getting issues reported on the tracker

for (int x = px - scanHRadius; x <= px + scanHRadius; x++) {
for (int z = pz - scanHRadius; z <= pz + scanHRadius; z++) {
for (int y = Math.max(mc.level.getMinY(), py - scanVRadius); y <= py + scanVRadius; y++) {
if (callbacks.isEmpty()) break scan;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

prefer having the scan be a separate method over using label breaks


if (disableCurrent) {
iterator.remove();
completedCallbacks.add(callback);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the completedCallbacks list is redundant, you can just release the callback back into the pool here

Comment on lines +100 to +101
List<Runnable> callbacksToRun = new ReferenceArrayList<>(afterCallbacks);
afterCallbacks.clear();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

uselesss thread safety, module code should always be synchronous

@maartix1
maartix1 requested a review from crosby-moe November 10, 2026 23:12
@maartix1

Copy link
Copy Markdown
Contributor Author

Thanks for your feedback. I've made the necessary changes based on your suggestions. I've also implemented the recommended improvements to make the code cleaner and callback handling more straightforward. I appreciate your feedback.

@crosby-moe

Copy link
Copy Markdown
Collaborator

boolean scanCompleted isn’t doing anything
the try finally isn’t doing anything
List<Runnable> callbacksToRun = new ReferenceArrayList<>(afterCallbacks); i straight up already told you to undo

please dont let claude loose on classes when a 3 line pr would have sufficed

@crosby-moe crosby-moe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

^ this

@maartix1

Copy link
Copy Markdown
Contributor Author

boolean scanCompleted isn’t doing anything the try finally isn’t doing anything List<Runnable> callbacksToRun = new ReferenceArrayList<>(afterCallbacks); i straight up already told you to undo

please dont let claude loose on classes when a 3 line pr would have sufficed

I manually reverted the changes to the class you mentioned. Is my code okay now, or should I reduce the PR to just three lines?

@Big-Iron-Cheems
Big-Iron-Cheems merged commit 40db8a1 into MeteorDevelopment:master Nov 11, 2026
1 check passed
@maartix1
maartix1 deleted the new-pr-work branch November 11, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants