From f9b0941b3b09c75e911f043d341a4a26ed5606a6 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 2 Jun 2025 11:25:54 +0530 Subject: [PATCH] Fix loadedCallbackPending logic to properly prevent frame invalidation during Unity player creation --- .../flutter_unity_widget/FlutterUnityWidgetController.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetController.kt b/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetController.kt index a54132f8e..c9f272bfe 100755 --- a/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetController.kt +++ b/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetController.kt @@ -285,10 +285,12 @@ class FlutterUnityWidgetController( private fun createPlayer() { try { if (UnityPlayerUtils.activity != null) { + loadedCallbackPending = true UnityPlayerUtils.createUnityPlayer( this, object : OnCreateUnityViewCallback { override fun onReady() { // attach unity to controller attachToView() + loadedCallbackPending = false if (methodChannelResult != null) { methodChannelResult!!.success(true) @@ -298,6 +300,7 @@ class FlutterUnityWidgetController( }) } } catch (e: Exception) { + loadedCallbackPending = false if (methodChannelResult != null) { methodChannelResult!!.error("FLUTTER_UNITY_WIDGET", e.message, e) methodChannelResult!!.success(false) @@ -372,7 +375,6 @@ class FlutterUnityWidgetController( return } - loadedCallbackPending = false postFrameCallback { postFrameCallback { view.invalidate()