Catch exceptions in UnityPrepareRendererResources::free
#570
+43
−34
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.
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.