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

Mask queries don't work anymore #2616

Closed
2 tasks done
MineFact opened this issue Mar 12, 2024 · 10 comments · Fixed by #2617
Closed
2 tasks done

Mask queries don't work anymore #2616

MineFact opened this issue Mar 12, 2024 · 10 comments · Fixed by #2617
Labels
Approved Added if an issue has been approved by a maintainer Bug Something isn't working Good first issue Simple issue which would be a good first PR for newbies interested in contributing to the project

Comments

@MineFact
Copy link
Contributor

MineFact commented Mar 12, 2024

Server Implementation

Paper

Server Version

1.20.4

Describe the bug

queryRel Masks don't seem to work anymore. Whenever I try to use it, it doesn't work and spams the same NullPointerException Cannot invoke "com.sk89q.worldedit.internal.expression.ExpressionEnvironment.getBlockTypeRel(double, double, double)" because "this.environment" is null in the console over and over again.

  • I tried it with different servers even with ones that only have FAWE installed
  • I tried it with newest server versions and older server versions (1.19.4)
  • I tried it with newest and older FAWE versions till half a year ago
  • I tried it with normal WorldEdit and there it works. Only FAWE has this problem.
    => No matter what I do I can always reproduce this error with any queryRel and any mask or gmask that should produce a result but fails.

I also looked at the code and compiled it with some debug messages. Whenever I type the queryRel command, new Function classes get created and the Environment variable in the Function class is set. But once I execute the command another Function class is created but this time no Environment is set which then obviously leads to a NullPointerException.

What should I do now? I really need this to work and I'm willing to help out to fix this problem.

I talk about this line in the code but it will probably also fail for the other methods like query or queryAbs: https://github.com/IntellectualSites/FastAsyncWorldEdit/blob/main/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Functions.java#L425

To Reproduce

  1. Create a brush (e.g. //brush sphere stone)
  2. Create a mask with queryRel (e.g. //mask =queryRel(0,1,0,0,0) - Mask all blocks that have air above them)
  3. Click with the brush and see the errors in the console. Nothing gets replaced even though it should work.

Expected behaviour

Normally the queryRel should work. In my Steps to Reproduce example it should replace all surface blocks with stone.
It says that it worked but no blocks get placed and an error gets printed in the console.

Screenshots / Videos

image

Debug Messages:

  • FUNCTIONS CREATED message in Functions.java constructor
  • ENVIRONMENT SET message in Functions.setEnvironment() function
  • Environment check on command execution
    image

Error log (if applicable)

https://paste.gg/p/anonymous/a1cdb839af32405a98c6bcbd68ac0357

Fawe Debugpaste

https://athion.net/ISPaster/paste/view/89e8261d1a60492f859535bd46e51942

Fawe Version

2.9.1-SNAPSHOT

Checklist

Anything else?

No response

@MineFact MineFact added the Requires Testing This is a new issue which needs to be approved before labeled with "bug" label Mar 12, 2024
@OneLiteFeather
Copy link
Member

@IntellectualSites/core-team should we do a "Piston" label additionally? Looks like it is one of some breaking changes.

@SirYwell
Copy link
Member

That isn't caused by Piston. We clone the expression

public Expression clone() {
return new Expression(initialExpression, new HashSet<>(providedSlots));
}
we currently don't set the environment.

@OneLiteFeather
Copy link
Member

Is this an easy to fix issue or is it more a deeper issue that newcomers can't fix?

@SirYwell
Copy link
Member

From a quick look, the environment needs to be cloned as well (or it needs to be made thread-safe), but other than that, it should be pretty simple.

@OneLiteFeather OneLiteFeather added Bug Something isn't working Approved Added if an issue has been approved by a maintainer Good first issue Simple issue which would be a good first PR for newbies interested in contributing to the project and removed Requires Testing This is a new issue which needs to be approved before labeled with "bug" labels Mar 12, 2024
@MineFact
Copy link
Contributor Author

Thanks for the comments I took a look at it and yes it seems that cloning the expression but not setting the environment afterwards was the issue.

I fixed it in the code and now the issue is gone.

I only changed the clone function is this enough for pull request or does something else need to be changed as well? From my testing everything is fine with those changes.

These are the changes that I made:
https://github.com/MineFact/FastAsyncWorldEdit/blob/0e15e83cecfa51c2f9a095450873fb3c3b14646a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java#L200-L206

@SirYwell
Copy link
Member

If you look at https://github.com/IntellectualSites/FastAsyncWorldEdit/blob/e682917c437096885b84332cf421d62fc395bcf8/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java, there is a mutable field that is set for every block before evaluating the expression for that position. If multiple threads to that concurrently, things will break. I think there is no other sane way than also cloning/duplicating the environment.

@MineFact
Copy link
Contributor Author

@SirYwell
Copy link
Member

Feel free to open a Pull Request with these changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Added if an issue has been approved by a maintainer Bug Something isn't working Good first issue Simple issue which would be a good first PR for newbies interested in contributing to the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants