Skip to content

Commit 5cf5c61

Browse files
committed
(InputStateWindow) Added null checks to 'DrawHexDump' to avoid null reference errors and subscribed to device changed events - closing the window when the device is disconnected (this is done to avoid cached state from hanging around on reconnect)
1 parent 7924b18 commit 5cf5c61

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Packages/com.unity.inputsystem/InputSystem/Editor/Internal/InputStateWindow.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ public unsafe void InitializeWithControl(InputControl control)
113113
PollBuffersFromControl(control, selectBuffer: true);
114114

115115
titleContent = new GUIContent(control.displayName);
116+
117+
InputSystem.onDeviceChange += OnDeviceChange;
118+
}
119+
120+
private void OnDeviceChange(InputDevice device, InputDeviceChange change)
121+
{
122+
if (m_Control is null)
123+
return;
124+
125+
if (device.deviceId != m_Control.device.deviceId)
126+
return;
127+
128+
if (change == InputDeviceChange.Removed)
129+
Close();
130+
}
131+
132+
internal void OnDestroy()
133+
{
134+
if (m_Control != null)
135+
InputSystem.onDeviceChange -= OnDeviceChange;
116136
}
117137

118138
private unsafe void PollBuffersFromControl(InputControl control, bool selectBuffer = false)
@@ -286,6 +306,12 @@ private string FormatByte(byte value)
286306
////TODO: support dumping multiple state side-by-side when comparing
287307
private void DrawHexDump()
288308
{
309+
if (m_StateBuffers is null)
310+
return;
311+
312+
if (m_StateBuffers[m_SelectedStateBuffer] is null)
313+
return;
314+
289315
m_HexDumpScrollPosition = EditorGUILayout.BeginScrollView(m_HexDumpScrollPosition);
290316

291317
var stateBuffer = m_StateBuffers[m_SelectedStateBuffer];

0 commit comments

Comments
 (0)