Skip to content

Fix application freezing on macOS when trace_tracy is enabled#23201

Merged
alice-i-cecile merged 2 commits intobevyengine:mainfrom
xremming:tracy-macos-freeze-fix
Mar 21, 2026
Merged

Fix application freezing on macOS when trace_tracy is enabled#23201
alice-i-cecile merged 2 commits intobevyengine:mainfrom
xremming:tracy-macos-freeze-fix

Conversation

@xremming
Copy link
Copy Markdown
Contributor

@xremming xremming commented Mar 3, 2026

Objective

On macOS (26.3) enabling tracy for tracing causes Bevy to freeze here.

https://github.com/bevyengine/bevy/blob/release-0.18.1/crates/bevy_render/src/diagnostic/tracy_gpu.rs#L64

I assume this problem is likely related to the same root cause as #22365.

Solution

  • Don't create the tracy_client::GpuContext at all instead of creating a GpuContextType::Invalid. Whether this is "correct" is up to debate but it does fix the issue.

Testing

  • Run cargo run --example 3d_shapes -F bevy/trace_tracy without the patch -> example doesn't start and Tracy only gets events until the line linked above.
  • Run it with the patch and Tracy works, and the example starts.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@xremming xremming changed the base branch from main to release-0.18.1 March 3, 2026 12:36
@xremming xremming marked this pull request as ready for review March 3, 2026 12:43
@xremming xremming force-pushed the tracy-macos-freeze-fix branch from e7e8bfb to e7fcc1d Compare March 3, 2026 12:47
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-23201

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@kfc35 kfc35 added O-MacOS Specific to the MacOS (Apple) desktop operating system C-Bug An unexpected or incorrect behavior S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Rendering Drawing game state to the screen labels Mar 3, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering Mar 3, 2026
@kfc35 kfc35 added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Mar 3, 2026
@kfc35
Copy link
Copy Markdown
Contributor

kfc35 commented Mar 3, 2026

@xremming Just confirming that you meant to point this PR to be merged into the release-0.18.1 branch? Since 0.18.1 has been released already, I think it might be too late to merge a fix into that branch.

Does this issue appear on main? If so, I think it’s better to point this PR to be merged into main, and then we can tag it appropriately for inclusion in the correct milestone

@alice-i-cecile alice-i-cecile added the S-Needs-Testing Testing must be done before this is safe to merge label Mar 3, 2026
@alice-i-cecile
Copy link
Copy Markdown
Member

Indeed: we should point this to main, then cherrypick it to 0.18.2 if needed.

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 3, 2026
@alice-i-cecile alice-i-cecile added this to the 0.18.2 milestone Mar 3, 2026
@alice-i-cecile alice-i-cecile requested a review from aevyrie March 3, 2026 16:48
@xremming
Copy link
Copy Markdown
Contributor Author

xremming commented Mar 3, 2026

@kfc35 I did indeed point this to 0.18.1 branch for a reason, which is that it's where I made the fix at for myself for (and tested it). I can rebase this to main if that's preferable.

However 0.18.1 is not yet released at crates.io?

@alice-i-cecile
Copy link
Copy Markdown
Member

I can rebase this to main if that's preferable.

Yes, this needs to be rebased :)

However 0.18.1 is not yet released at crates.io?

Correct; just waiting for final sign-off from fellow maintainers.

@xremming xremming force-pushed the tracy-macos-freeze-fix branch from e7fcc1d to 8a86699 Compare March 3, 2026 17:27
@xremming xremming changed the base branch from release-0.18.1 to main March 3, 2026 17:27
@xremming
Copy link
Copy Markdown
Contributor Author

xremming commented Mar 3, 2026

Rarely does a rebase work on the first try as intended... Nice.

Tested it out with and without the patch on main against the 3d_shapes example and can confirm the fix still works (and is still required).

@xremming
Copy link
Copy Markdown
Contributor Author

xremming commented Mar 3, 2026

Would be interesting if someone with an older macOS version could test this. Seeing that it has worked on macOS previously, at least based on the profiling.md that has a screenshot from macOS.

This also made me wonder if this will need to be gated on iOS too. 🤔 I remember seeing an issue about supporting Tracy on iOS and Android. Perhaps another PR will be required to rework the GPU profiling based on support for it.

@kfc35 kfc35 added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Mar 4, 2026
@xremming xremming requested a review from aevyrie March 18, 2026 12:01
@xremming xremming force-pushed the tracy-macos-freeze-fix branch 2 times, most recently from 566aa73 to e3839c5 Compare March 20, 2026 22:20
@xremming
Copy link
Copy Markdown
Contributor Author

If possible, could also be useful to also build and test the examples on macOS with Tracy enabled. That should make sure this doesn't happen again.

@xremming xremming requested a review from kfc35 March 20, 2026 22:32
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

This looks correct and doesn’t seem unreasonable. I agree with the logic that we should just return none for unsupported backends

Copy link
Copy Markdown
Contributor

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

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

I've tested this code on macos and it does prevent hangs when using tracy features. That said, I don't understand the fix, and the fix isn't explained in the PR, so I'm not sure anyone currently understands it. I will approve this on the condition that it fixes the crash and is easily revertible, with the following context:

We copy this code from Wumpf/wgpu-profiler, which I've run and also exhibits a similar issue on macos. I filed an issue so they are also aware, since we copy their code.

I can't find where or why the behavior for the equivalent of Poll::wait_indefinitely changed on macos (which is where the hang is occurring), and this PR currently fixes it by not creating the Tracy client, and thus not setting a section of tracy-related span information, which seems like a difference in behavior that we aren't checking.

I feel like there should be a PR somewhere or a code change (perhaps in wgpu?) that we can point to to understand what happened here, but I can't find it.

@kfc35 kfc35 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge labels Mar 20, 2026
@xremming xremming force-pushed the tracy-macos-freeze-fix branch 2 times, most recently from 7aae6d1 to fa82a1f Compare March 21, 2026 18:30
@xremming
Copy link
Copy Markdown
Contributor Author

xremming commented Mar 21, 2026

Amended the commit to include a comment explaining why the function is returning an optional (and removed the original short-circuiting fix commit so this is easy to revert).

mockersf and others added 2 commits March 21, 2026 20:36
The unsupported backends used to be mapped to `GpuContextType::Invalid`,
changed it to instead use `None` in those cases. This assumes that the
`Invalid` type was actually not doing any work.
@xremming xremming force-pushed the tracy-macos-freeze-fix branch from fa82a1f to c6d326c Compare March 21, 2026 18:36
@ChristopherBiscardi
Copy link
Copy Markdown
Contributor

new comment suitably addresses my concerns about notifying future readers about the ambiguity of the source of the issue

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 21, 2026
Merged via the queue into bevyengine:main with commit 08eaaec Mar 21, 2026
38 checks passed
@github-project-automation github-project-automation bot moved this from Needs SME Triage to Done in Rendering Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples O-MacOS Specific to the MacOS (Apple) desktop operating system S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants