Skip to content

Commit 76568b1

Browse files
author
Oskari Leppäaho
committed
Fix a deadlock, GetNativeText no longer works
We used to get a deadlock when Unity was listening to the NativeEditBox.returnPressed event and called SetFocusNative on another NativeEditBox on that event, which resulted in a TextEndEdit message to be sent to Unity (which never arrived on Unity side). Not 100 % sure why that was the case, but removing the waiting for EditBox.processRecvJsonMsg results in SendUnityMsgToPlugin seems to solve the issue. As we don’t wait for the result anymore, we can’t return a message to Unity. Fortunately that was only used for the NativeEditBox.GetTextNative() method, which isn’t necessary because we update the Unity InputField text when the native text is changed.
1 parent 1f58a67 commit 76568b1

4 files changed

Lines changed: 8 additions & 29 deletions

File tree

-396 Bytes
Binary file not shown.

release/NativeEditPlugin/scripts/NativeEditBox.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ public void SetTextNative(string newText)
295295
this.SendPluginMsg(jsonMsg);
296296
}
297297

298+
// GetTextNative won't work on Android, because of threading issues. It should not be needed though,
299+
// as the Unity InputField's text property is updated as the native text changes, so it should match
300+
// the native text.
301+
#if !UNITY_ANDROID
298302
public string GetTextNative()
299303
{
300304
JsonObject jsonMsg = new JsonObject();
@@ -308,6 +312,7 @@ public string GetTextNative()
308312
Debug.Log(string.Format("GetTextNative {0}", jsonRet.GetString("text")));
309313
return jsonRet.GetString("text");
310314
}
315+
#endif
311316

312317
private void RemoveNative()
313318
{

src/androidProj/nativeeditplugin/src/main/java/com/bkmin/android/EditBox.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class EditBox {
4343
private static String MSG_CREATE = "CreateEdit";
4444
private static String MSG_REMOVE = "RemoveEdit";
4545
private static String MSG_SET_TEXT = "SetText";
46-
private static String MSG_GET_TEXT = "GetText";
4746
private static String MSG_SET_RECT = "SetRect";
4847
private static String MSG_SET_FOCUS = "SetFocus";
4948
private static String MSG_SET_VISIBLE = "SetVisible";
@@ -138,11 +137,6 @@ else if (msg.equals(MSG_SET_TEXT))
138137
String text = jsonMsg.getString("text");
139138
this.SetText(text);
140139
}
141-
else if (msg.equals(MSG_GET_TEXT))
142-
{
143-
String text = this.GetText();
144-
jsonRet.put("text", text);
145-
}
146140
else if (msg.equals(MSG_SET_RECT))
147141
{
148142
this.SetRect(jsonMsg);

src/androidProj/nativeeditplugin/src/main/java/com/bkmin/android/NativeEditPlugin.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,33 +123,13 @@ public static void SendUnityMessage(JSONObject jsonMsg)
123123
UnityPlayer.UnitySendMessage(unityName, "OnMsgFromPlugin", jsonMsg.toString());
124124
}
125125

126-
static JSONObject jsonStaticRet = null;
127126
public static String SendUnityMsgToPlugin(final int nSenderId, final String jsonMsg) {
128127
final Runnable task = new Runnable() {
129128
public void run() {
130-
jsonStaticRet = EditBox.processRecvJsonMsg(nSenderId, jsonMsg);
131-
synchronized (this) {
132-
this.notify();
133-
}
129+
EditBox.processRecvJsonMsg(nSenderId, jsonMsg);
134130
}
135131
};
136-
synchronized (task) {
137-
unityActivity.runOnUiThread(task);
138-
try
139-
{
140-
task.wait();
141-
}
142-
catch ( InterruptedException e )
143-
{
144-
e.printStackTrace();
145-
}
146-
}
147-
148-
if (jsonStaticRet != null) {
149-
return jsonStaticRet.toString();
150-
}
151-
else {
152-
return "";
153-
}
132+
unityActivity.runOnUiThread(task);
133+
return new JSONObject().toString();
154134
}
155135
}

0 commit comments

Comments
 (0)