I have a command-line app experiencing this issue. It uses CVDisplayLink to render directly to a window through Metal. Apple recently deprecated CVDisplayLink and introduced a new recommended API, CAMetalDisplayLink. It has the same restrictions as CADisplayLink and prevents the user from having true low-level control over frame synchronization. The other apps mentioned with this bug rely on OpenGL and other frameworks, which likely delegate directly to CVDisplayLink. This might explain why a strange subset of all apps are affected by the bug.
The solution for my use case, was to launch the app from swift run on command-line w/ SwiftPM, which is how it would run on non-Apple platforms as well. But my solution may not be the best for other people. Alternatively, you can add an intentional ≥350 ms delay upon app startup. The workaround sleep(1) worked because it introduced a 1000 ms delay, ~three times what is actually needed.
https://github.com/philipturner/molecular-renderer/commit/655e367ef5a33218d7fc5654ded2ff8a282ff804
// WARNING: Do not launch the application from the Xcode UI on macOS 15.
// There is a bug that makes it launch the application 3 times:
// https://www.reddit.com/r/Xcode/comments/1g7640w/xcode_starting_running_my_programs_twice/
// https://developer.apple.com/forums/thread/765445
//
// Remedies:
// - Unchecking 'debug executable' in the Xcode scheme for 'Workspace':
// - Reduces the number of launches from 3 to 2.
// - Delaying with sleep:
// - sleep(1) from the forums is 1 s (1000 ms), an incredibly large delay.
// Duplicated windows stop appearing once the delay approaches ~350 ms
// on my machine. Use usleep(400_000) for 400 ms delay, or refine to
// 50 ms above the value that consistently works on your machine.
// - Switching to release mode in the Xcode scheme for 'Workspace':
// - The number of launches is still 3.
// - Only launching from a SwiftPM console workflow ('swift run'):
// - Effectively solves the problem.
//
// Can you auto-detect whether it's being launched from SwiftPM?
//
// No.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: