Skip to content

fix(sound): stop the untracked ambience copy before restarting it - #1302

Open
Zoobooo wants to merge 3 commits into
Polyfrost:v1from
Zoobooo:fix/ambience-orphaned-copy
Open

Zoobooo wants to merge 3 commits into
Polyfrost:v1from
Zoobooo:fix/ambience-orphaned-copy

Conversation

@Zoobooo

@Zoobooo Zoobooo commented Nov 4, 2026

Copy link
Copy Markdown

Description

On 1.8.9, turning off UI Ambience (or closing the menu) sometimes leaves the music playing.

Cause: the ambience watch loop in McUiSoundService.driveAmbienceLoop restarts the track when soundManager.isActive(current) is false, but it never stops current before replacing ambience. On 1.8.9 that check can be false for a sound that is actually starting:

  • Paulscode's play() only queues a command, so sndSystem.playing() is false until the command thread and stream thread have started the source.
  • For the first 20 ticks vanilla's SoundManager.isSoundPlaying only relies on sndSystem.playing().
  • Queued addScheduledTask tasks run back to back in one frame, so after a main thread stall over 500 ms several checks run in a row and each one sees the brand new instance as inactive.

Each hit starts another copy and drops the reference to the previous one. stopAmbience only fades the tracked instance, so the dropped copies keep playing. With the Polyglass pad (natively looping) they never end.

Fix: stop current before starting the replacement. Every place that replaces ambience now stops the old instance first (startAmbience already did). On 1.21 isActive is accurate, so the added stop is a no-op for an already finished sound.

Trade-off: if the check still lands in that window, the track restarts once instead of a duplicate being left behind.

Testing: not built or tested in game yet. The diagnosis comes from reading OneConfig's code alongside the 1.8.9 SoundManager and Paulscode sources.

Related Issue(s)

None filed. Reported on 1.8.9 while playing on Hypixel.

Checklist

  • I made a clear description of what was changed
  • I stated why these changes were necessary
  • I updated documentation or said what needs to be updated (no docs affected)
  • I made sure these changes are backwards compatible (internal class only)
  • This pull request is for one feature/bug fix

@lunaynx
lunaynx force-pushed the fix/ambience-orphaned-copy branch 2 times, most recently from 9468602 to 930e84d Compare November 15, 2026 20:21
Comment on lines +221 to +223
// 1.8.9 starts streams on Paulscode's threads, so a fresh stream reports inactive until its preload ends.
// Stopping it then is lost: preload finishes afterwards and starts the channel untracked.
// A zero-volume play is skipped by the engine, so it never starts and gets no grace.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an overly verbose comment. I personally would just remove this as it's not really needed. This can just be explained in the PR.

@lunaynx
lunaynx force-pushed the v1 branch 4 times, most recently from 6fea82e to d7a54ab Compare November 20, 2026 18:18
Zoobooo and others added 3 commits November 21, 2026 15:15
On 1.8.9 sounds start asynchronously, so a stream that was just started can still report inactive for up to 20 ticks. When the ambience watch loop hit that window it started a new copy and dropped the reference to the old one, which kept playing. stopAmbience only fades the tracked copy, so turning UI Ambience off or closing the menu left the music playing (forever for the looping Polyglass pad).
@lunaynx
lunaynx force-pushed the fix/ambience-orphaned-copy branch from 930e84d to d85f569 Compare November 21, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants