Skip to content

Catch exceptions in UnityPrepareRendererResources::free #570

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

Merged
merged 2 commits into from
Apr 30, 2025
Merged

Conversation

kring
Copy link
Member

@kring kring commented Apr 30, 2025

I noticed while testing #567 that Unity is a bit crashy when reloading AppDomains, which happens every time we enter or exit Play mode. This has always been an issue (see #561) but I think it has gotten worse with the multiple viewports changes. I don't think there is anything wrong with the multiple viewports feature itself, it just changes the timing of object destruction slightly.

As always, a "good" solution is elusive. But this PR improves the situation by adding a pokemon exception handler to UnityPrepareRendererResources::free. This function is on the critical path of AppDomain reloads, and oftens triggers exceptions when the managed world, now in a new AppDomain, is different from the one that the native objects from the previous AppDomain expect. By catching and ignoring these exceptions locally, rather than allowing them to propagate, we grealy reduce the chances of cascading failures.

I saw much improved stability when entering and exiting Play mode after making these changes.

@kring kring added this to the May 2025 Release milestone Apr 30, 2025
@kring
Copy link
Member Author

kring commented Apr 30, 2025

@azrogers can I bug you to test this one, since you wrote #561?

@kring kring requested a review from azrogers April 30, 2025 11:15
@azrogers
Copy link
Contributor

@kring Seems to work well, haven't experienced any crashes while using it. I doubt this entirely solves our AppDomain reload issue but it's a big step forward. Thanks!

@azrogers azrogers merged commit 9a436ac into main Apr 30, 2025
7 checks passed
@azrogers azrogers deleted the catch-em-all branch April 30, 2025 15:45
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.

2 participants