Anr fix "com.unity3d.player.UnityPlayer.nativeRender" #999
+5
−2
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.
Description
This PR introduces a fix for the ANR (Application Not Responding) issue:
com.unity3d.player.UnityPlayer.nativeRender
in the flutter_unity_widget package. The ANR issue was caused by attempting to send Unity messages when the Unity player was not properly loaded or initialized.Changes Made:
Modified Function:
Type of Change
Motivation and Context
The ANR issue was reported with the following trace:
com.unity3d.player.UnityPlayer.nativeRender (UnityPlayer.java) com.unity3d.player.UnityPlayer$C$a.handleMessage (UnityPlayer.java:123) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loopOnce (Looper.java:226) android.os.Looper.loop (Looper.java:313) com.unity3d.player.UnityPlayer$C.run (UnityPlayer.java:25)
By adding a check for unityPlayer and unityLoaded before sending messages, we prevent calls to Unity when it is not ready, thus mitigating the ANR.
How Has This Been Tested?
Additional Notes
This fix addresses the ANR without introducing any breaking changes.
Verified compatibility with Unity versions 2021 and above.
✨ New feature (non-breaking change which adds functionality)
🛠️ Bug fix (non-breaking change which fixes an issue)
❌ Breaking change (fix or feature that would cause existing functionality to change)
🧹 Code refactor
✅ Build configuration change
📝 Documentation
🗑️ Chore