Skip to content

Commit

Permalink
(InputStateWindow) Added null checks to 'DrawHexDump' to avoid null r…
Browse files Browse the repository at this point in the history
…eference 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)
  • Loading branch information
Secticide committed Dec 18, 2024
1 parent 7924b18 commit 5cf5c61
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ public unsafe void InitializeWithControl(InputControl control)
PollBuffersFromControl(control, selectBuffer: true);

titleContent = new GUIContent(control.displayName);

InputSystem.onDeviceChange += OnDeviceChange;
}

private void OnDeviceChange(InputDevice device, InputDeviceChange change)
{
if (m_Control is null)
return;

if (device.deviceId != m_Control.device.deviceId)
return;

if (change == InputDeviceChange.Removed)
Close();
}

internal void OnDestroy()
{
if (m_Control != null)
InputSystem.onDeviceChange -= OnDeviceChange;
}

private unsafe void PollBuffersFromControl(InputControl control, bool selectBuffer = false)
Expand Down Expand Up @@ -286,6 +306,12 @@ private string FormatByte(byte value)
////TODO: support dumping multiple state side-by-side when comparing
private void DrawHexDump()
{
if (m_StateBuffers is null)
return;

if (m_StateBuffers[m_SelectedStateBuffer] is null)
return;

m_HexDumpScrollPosition = EditorGUILayout.BeginScrollView(m_HexDumpScrollPosition);

var stateBuffer = m_StateBuffers[m_SelectedStateBuffer];
Expand Down

0 comments on commit 5cf5c61

Please sign in to comment.