Repository navigation
fix(macos): stop per-frame environment refreshes and camera probes - #2821
Merged
Merged
Conversation
Probe the camera once and follow AVCaptureDevice connect and disconnect notifications instead of running AVFoundation device discovery twice on every environment refresh. Coalesce the refreshes that display parameter, screen, screen profile and backing scale notifications request in one run loop turn, and rate-limit environments that change only displays' HDR headroom to four a second, with a trailing refresh that publishes the settled value. Fixes #2813
|
The |
houko
added a commit
to nsgo-dev/orbit-academy-game
that referenced
this pull request
Dec 1, 2026
…ayer main Move to nsgo main (8e5c1cc), which opens the main window maximized from its first frame (nsgo-dev/nsgo#2822) and brings the environment refresh (nsgo-dev/nsgo#2821) and sprite-frame crop cache (nsgo-dev/nsgo#2817) fixes, and to the game layer main (be78552), which builds against it (nsgo-dev/game#2723). Replace maximizeOnce, which waited for the first window frame to toggle maximize, with nsgo.WindowMaximized in main.go, and migrate the one numeric FlexShrink to core.Shrink.
houko
added a commit
to nsgo-dev/orbit-academy-game
that referenced
this pull request
Dec 1, 2026
…ayer main (#5) Move to nsgo main (8e5c1cc), which opens the main window maximized from its first frame (nsgo-dev/nsgo#2822) and brings the environment refresh (nsgo-dev/nsgo#2821) and sprite-frame crop cache (nsgo-dev/nsgo#2817) fixes, and to the game layer main (be78552), which builds against it (nsgo-dev/game#2723). Replace maximizeOnce, which waited for the first window frame to toggle maximize, with nsgo.WindowMaximized in main.go, and migrate the one numeric FlexShrink to core.Shrink.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On macOS, every environment refresh asked AVFoundation for the default camera twice, and a display brightness ramp produced a new environment on every frame because the display snapshot's HDR headroom steps with the brightness. This change:
AVCaptureDeviceWasConnectedNotification/AVCaptureDeviceWasDisconnectedNotification; a change of availability requests a refresh of every surface (internal/platform/macos/camera.go).viewDidChangeBackingProperties,NSWindowDidChangeScreenNotification,NSWindowDidChangeScreenProfileNotificationandNSApplicationDidChangeScreenParametersNotification. A directrefresh()in between satisfies a waiting request. Other notifications (resize, move, full screen, key, activation) still refresh synchronously, as their handlers depend on the order.HDRHeadroomto one per 250 ms. A held change schedules one trailing refresh at the end of the interval, so the value the display settles at is always published. Any other change, including entering or leaving HDR, goes through at once (internal/platform/macos/refresh.go).Which notification drives the per-frame refresh during a ramp could not be confirmed without a display to ramp; all candidates named in the issue are now coalesced, and the headroom gate limits the updates whichever one fires.
Other backends: iOS already caches camera availability (
cameraAvailable, async.OnceValueoverUIImagePickerController) and refreshes only on discrete UIKit notifications, so it needs no change. Windows and Wayland Linux report a headroom derived from static display luminance values, not a brightness-tracking current value.Fixes #2813
Targets
core,base,ui,tsx, thensgotool)Screenshots
None
Verification
Tests were written first. Before the fix (probe seam only, old behavior):
The coalescer, headroom gate and camera watch tests did not build before (
undefined: cameraWatch,coalescer,headroomOnly,headroomGate). After:TestHeadroomGateLimitsARampsteps the headroom every frame at 120 Hz for one second and requires at most 5 published environments and the settled value published at the end.The full
internal/platform/macosrun fails onlyTestInputMethodCommitAndSinkCandidates("timed out waiting for test window active and key"), which needs a window session; it fails identically onmainat fd02adf on the same machine (main: 155 passed, 1 failed; this branch: 160 passed, 1 failed).e26a142217a8912e2dc0664ba9c43e226f77da22fd02adf8ed86177303d3db4d5a3ee119690c8175go tool nsgo check -target macos,ios→ 0go tool nsgo test ./internal/platform/apple/→ 0go tool nsgo test ./internal/platform/macos/→ 1 (onlyTestInputMethodCommitAndSinkCandidates, which needs an active key window and fails the same way on the base commit)go tool nsgo test ./internal/moduletest/→ 0go run ./tools/changelog check→ 0failChecklist
fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.changelog.d/fragment, not inCHANGELOG.md.