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

Catch async usage of playsound #10021

Merged
merged 3 commits into from
Dec 26, 2023
Merged

Conversation

Owen1212055
Copy link
Member

This causes the world random to scream due to multi-thread acces

@Owen1212055 Owen1212055 requested a review from a team as a code owner December 11, 2023 01:28
@Machine-Maker
Copy link
Member

Do we also need catchers for the adventure sound methods? Should be added to the adventure patch if so.

@Owen1212055 Owen1212055 changed the title Don't allow async sounds that access seed Catch async usage of playsound in unsafe circumstances Dec 26, 2023
@Owen1212055 Owen1212055 changed the title Catch async usage of playsound in unsafe circumstances Catch async usage of playsound Dec 26, 2023
Copy link
Member

@Machine-Maker Machine-Maker left a comment

Choose a reason for hiding this comment

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

Looks good. This was expanded to catch any use of World#playSound off the main thread as none of the 3 methods are thread-safe. It does more specific checks for Server#playSound methods as there are some cases where the use is thread-safe.

@Owen1212055 Owen1212055 merged commit dc62150 into PaperMC:master Dec 26, 2023
3 checks passed
@Owen1212055 Owen1212055 deleted the no-async-sounds branch December 26, 2023 20:00
@ghost
Copy link

ghost commented Dec 27, 2023

In my opinion this is a bad idea, .playSound is just sending a packet, same as .spawnParticle people will use it async. If the world random is screaming use the multithreaded random, why does world random even matter when playing a sound

@ghost
Copy link

ghost commented Dec 27, 2023

also wat
image

@Machine-Maker
Copy link
Member

Machine-Maker commented Dec 27, 2023

.playSound is just sending a packet

Very much not true on World and Server. On Player, playSound is as simple as sending a packet. But not on those other types. They either iterate over a thread-unsafe list of players in a world or use the vanilla packet broadcasting system based on location which contains thread-unsafe logic.

The "world random" aspect is just one part of this. If a sound isn't provided a seed, a seed must be generated from the world's random instance which is a thread-unsafe instance.

As to your second post, I'm not sure what you are "wat"ing? THat diff is just changing some hunk line numbers and index hashes.

EDIT: Feel free to ping me in the discord if you want to discuss this further (@machinemaker)

@ghost
Copy link

ghost commented Dec 27, 2023

.playSound is just sending a packet

Very much not true on World and Server. On Player, playSound is as simple as sending a packet. But not on those other types. They either iterate over a thread-unsafe list of players in a world or use the vanilla packet broadcasting system based on location which contains thread-unsafe logic.

The "world random" aspect is just one part of this. If a sound isn't provided a seed, a seed must be generated from the world's random instance which is a thread-unsafe instance.

As to your second post, I'm not sure what you are "wat"ing? THat diff is just changing some hunk line numbers and index hashes.

EDIT: Feel free to ping me in the discord if you want to discuss this further (@machinemaker)

It appears the line

lighning.isSilent = isSilent

was removed, I could be mistaken though.

@Machine-Maker
Copy link
Member

It appears the line
lighning.isSilent = isSilent
was removed, I could be mistaken though.

That's correct. That line was removed. But not as a part of this PR. That is just part of an existing patch that removes that line.
image
These 3 spots are the lines in that patch that changed as a result of this PR.

CryptoMorin added a commit to CryptoMorin/XSeries that referenced this pull request Dec 30, 2023
Since paper now blocks async location-based sound plays (PaperMC/Paper#10021), I decided to use my own system.
lynxplay pushed a commit to lynxplay/paper that referenced this pull request Feb 23, 2024
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.

None yet

3 participants