- Home /
each character doubled in inputfield in build but not editor on ubuntu 16.04
Since upgrading to 2017.3.0f1 (from 2.0f3), I have a strange problem with an UI input field where each typed character is doubled:
"hello, world" --> "hheelllloo,, wwoorrlldd"
This is not happening when I play in the editor, but only when I build. I can reproduce the problem with a fresh game that consists of just the base scene and an input field. (happy to attach a file, but it's really simple to reproduce). The same minimal project works normally when compiled using 2017.2.0f3.
I'm reluctant to submit it as a bug because strangely enough the compiled game runs normally on an archlinux system (I mean the actual file compiled on the ubuntu machine works normally on the arch machine).
the game works normally when compiled for windows by a windows version of the 2017.3 editor.
So the setup with the weird behavior is running Ubuntu 16.04 with Unity 2017.3.0f1.
I don't really know where to begin trouble shooting this.
any suggestions greatly appreciated.
Answer by lolisamurai · Jan 04, 2018 at 03:11 PM
same issue here. i tried debugging unity's InputField and it appears that the Event.PopEvent
loop gets two keyDown events instead of one... i guess the problem is related to some change they did to the native code that deals with xlib events on linux. guess I'm gonna be opening a bug report since they don't have a public source to check and I'm not too good at reverse engineering /shrug
here is a temporary horrible workaround for the issue. if you want to be sure it doesn't break when they change InputField's internals you are better off making an entire copy of the class with the workaround.
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Reflection;
// a horrible hack to work around input duplication bugs on linux
public class InputFieldWithWorkarounds : InputField {
int keyDownCount = 0;
bool workAroundDuplicatedKeystrokesBug = false;
static FieldInfo GetPrivateFieldObject(string name) {
return typeof(InputField).GetField (
name, BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance
);
}
void SetPrivateField(string name, System.Object value) {
GetPrivateFieldObject (name).SetValue (this, value);
}
System.Object GetPrivateField(string name) {
return GetPrivateFieldObject (name).GetValue (this);
}
bool m_ShouldActivateNextUpdate {
set { SetPrivateField ("m_ShouldActivateNextUpdate", (System.Object)value); }
get { return (bool)GetPrivateField ("m_ShouldActivateNextUpdate"); }
}
Event m_ProcessingEvent {
set { SetPrivateField ("m_ProcessingEvent", (System.Object)value); }
get { return (Event)GetPrivateField ("m_ProcessingEvent"); }
}
void ActivateInputFieldInternal() {
MethodInfo method = typeof(InputField).GetMethod(
"ActivateInputFieldInternal", BindingFlags.NonPublic | BindingFlags.Instance
);
method.Invoke(this, new object[] {});
}
protected override void Start () {
base.Start ();
workAroundDuplicatedKeystrokesBug = Application.unityVersion == "2017.3.0f1"
&& Application.platform == RuntimePlatform.LinuxPlayer;
}
public override void OnUpdateSelected(BaseEventData eventData)
{
if (!workAroundDuplicatedKeystrokesBug) {
base.OnUpdateSelected (eventData);
return;
}
// Only activate if we are not already activated.
if (m_ShouldActivateNextUpdate)
{
if (!isFocused)
{
ActivateInputFieldInternal();
m_ShouldActivateNextUpdate = false;
return;
}
// Reset as we are already activated.
m_ShouldActivateNextUpdate = false;
}
if (!isFocused)
return;
bool consumedEvent = false;
while (Event.PopEvent(m_ProcessingEvent))
{
Event ev = m_ProcessingEvent;
if (ev.rawType == EventType.KeyDown)
{
if (ev.keyCode != KeyCode.Return && keyDownCount++ % 2 != 0) {
continue;
}
consumedEvent = true;
var shouldContinue = KeyPressed(ev);
if (shouldContinue == EditState.Finish)
{
DeactivateInputField();
break;
}
}
}
if (consumedEvent)
UpdateLabel();
eventData.Use();
}
}
I opened a bug report here: https://fogbugz.unity3d.com/default.asp?984740_fsdqmmud49i76sdo
UPDATE: I updated the workaround with a few $$anonymous$$or fixes for bugs i encountered with further testing
Answer by ratchet01 · Feb 15, 2018 at 05:13 PM
This is a known regression. The bug is tracked here: https://issuetracker.unity3d.com/issues/linux-keystrokes-recorded-twice If you are affected by this issue, please upvote the issuetracker page. (lolisamurai's bug report posted in comments was closed as a duplicate)
Your answer
Follow this Question
Related Questions
How to made VsCode default editor on Ubuntu? 2 Answers
Building asset bundles on an ubuntu docker container 1 Answer
Ubuntu Editor and "Dash To Panel" GNOME Shell extension issue 0 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
How to run the exported game on ubuntu 5 Answers