@dr33m/react-native-litert-lm 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -749,14 +749,36 @@ class HybridLiteRTLM : HybridLiteRTLMSpec() {
|
|
|
749
749
|
// for it while holding the lock would block loadModel behind it.
|
|
750
750
|
cancelInFlightGeneration()
|
|
751
751
|
synchronized(initLock) {
|
|
752
|
+
/*
|
|
753
|
+
* Dropped first, closed second.
|
|
754
|
+
*
|
|
755
|
+
* These used to be nulled after their `close()` calls, inside one
|
|
756
|
+
* try. A close that threw — and closing a conversation that has
|
|
757
|
+
* just been cancelled is exactly when one does — skipped the rest
|
|
758
|
+
* of the block and left a retired engine still referenced. Nothing
|
|
759
|
+
* downstream could tell: `isReady()` reads `engine != null`, so the
|
|
760
|
+
* instance went on reporting itself loaded, and the next
|
|
761
|
+
* `resetConversation()` called `createConversation` on a closed
|
|
762
|
+
* engine and threw "Engine is not initialized" from deep in the SDK.
|
|
763
|
+
*
|
|
764
|
+
* Letting go of the references first makes that impossible: after
|
|
765
|
+
* this block the instance is unloaded whatever the native side did.
|
|
766
|
+
*/
|
|
767
|
+
val retiredConversation = conversation
|
|
768
|
+
val retiredEngine = engine
|
|
769
|
+
conversation = null
|
|
770
|
+
engine = null
|
|
771
|
+
loadedModelPath = null
|
|
772
|
+
|
|
773
|
+
try {
|
|
774
|
+
retiredConversation?.close()
|
|
775
|
+
} catch (e: Exception) {
|
|
776
|
+
Log.w(TAG, "Error closing conversation: ${e.message}")
|
|
777
|
+
}
|
|
752
778
|
try {
|
|
753
|
-
|
|
754
|
-
conversation = null
|
|
755
|
-
engine?.close() // Direct call
|
|
756
|
-
engine = null
|
|
757
|
-
loadedModelPath = null
|
|
779
|
+
retiredEngine?.close()
|
|
758
780
|
} catch (e: Exception) {
|
|
759
|
-
Log.
|
|
781
|
+
Log.w(TAG, "Error closing engine: ${e.message}")
|
|
760
782
|
}
|
|
761
783
|
}
|
|
762
784
|
}
|
|
@@ -825,7 +847,12 @@ class HybridLiteRTLM : HybridLiteRTLMSpec() {
|
|
|
825
847
|
// - Kotlin: Not yet available — track at https://github.com/google-ai-edge/LiteRT-LM
|
|
826
848
|
//
|
|
827
849
|
// Once the Kotlin SDK exposes this, wire it via ConversationConfig here.
|
|
828
|
-
|
|
850
|
+
// Checked rather than forced: this runs from `resetConversation`, which
|
|
851
|
+
// JS calls on paths that do not first ask whether anything is loaded.
|
|
852
|
+
// A named error beats a null-pointer dereference from inside the SDK.
|
|
853
|
+
val activeEngine = engine
|
|
854
|
+
?: throw RuntimeException("Cannot create a conversation: no model is loaded.")
|
|
855
|
+
conversation = activeEngine.createConversation(convConfig)
|
|
829
856
|
}
|
|
830
857
|
|
|
831
858
|
|