-
Notifications
You must be signed in to change notification settings - Fork 329
FIX: out of range exception when pressing undo after creating and editing a new control scheme (ISXB-1607) #2237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 5 commits
e972f16
ce32d45
1b6175e
505f77d
f53e9a4
31800be
cf3f6a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using UnityEditor; | ||
using UnityEditor.UIElements; | ||
using UnityEngine.UIElements; | ||
|
@@ -24,6 +25,8 @@ | |
|
||
private readonly Action m_SaveAction; | ||
|
||
private ControlSchemesView m_ControlSchemesView; | ||
|
||
public InputActionsEditorView(VisualElement root, StateContainer stateContainer, bool isProjectSettings, | ||
Action saveAction) | ||
: base(root, stateContainer) | ||
|
@@ -104,6 +107,27 @@ | |
}); | ||
|
||
s_OnPasteCutElements.Add(this); | ||
|
||
Undo.undoRedoPerformed += CheckForInvalidControlSchemeInOneFrame; | ||
} | ||
|
||
private async void CheckForInvalidControlSchemeInOneFrame() | ||
{ | ||
Check warning on line 115 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs
|
||
try | ||
{ | ||
await Task.Delay(1); | ||
|
||
var state = stateContainer.GetState(); | ||
var viewState = ViewStateSelector.GetViewState(state); | ||
var elementAtOrDefault = viewState.controlSchemes?.ElementAtOrDefault(viewState.selectedControlSchemeIndex); | ||
if (viewState.selectedControlSchemeIndex != -1 && elementAtOrDefault == default(InputControlScheme)) | ||
{ | ||
m_ControlSchemesView?.Cancel(); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogException(e); | ||
} | ||
Check warning on line 130 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs
|
||
} | ||
|
||
private void OnReset() | ||
|
@@ -156,9 +180,8 @@ | |
|
||
if (viewState.controlSchemes.Any()) | ||
{ | ||
m_ControlSchemesToolbar.text = viewState.selectedControlSchemeIndex == -1 | ||
? "All Control Schemes" | ||
: viewState.controlSchemes.ElementAt(viewState.selectedControlSchemeIndex).name; | ||
var elementAtOrDefault = viewState.controlSchemes.ElementAtOrDefault(viewState.selectedControlSchemeIndex); | ||
m_ControlSchemesToolbar.text = elementAtOrDefault == default ? "All Control Schemes" : elementAtOrDefault.name; | ||
Check warning on line 184 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs
|
||
|
||
m_ControlSchemesToolbar.menu.AppendAction("All Control Schemes", _ => SelectControlScheme(-1), | ||
viewState.selectedControlSchemeIndex == -1 ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal); | ||
|
@@ -186,7 +209,7 @@ | |
return; | ||
} | ||
m_DevicesToolbar.SetEnabled(true); | ||
var currentControlScheme = viewState.controlSchemes.ElementAt(viewState.selectedControlSchemeIndex); | ||
var currentControlScheme = viewState.controlSchemes.ElementAtOrDefault(viewState.selectedControlSchemeIndex); | ||
Check warning on line 212 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs
|
||
if (viewState.selectedDeviceIndex == -1) | ||
m_DevicesToolbar.text = "All Devices"; | ||
|
||
|
@@ -228,10 +251,13 @@ | |
|
||
private void ShowControlSchemeEditor(VisualElement parent, bool updateExisting = false) | ||
{ | ||
var controlSchemesView = CreateChildView(new ControlSchemesView(parent, stateContainer, updateExisting)); | ||
controlSchemesView.UpdateView(stateContainer.GetState()); | ||
|
||
controlSchemesView.OnClosing += _ => DestroyChildView(controlSchemesView); | ||
m_ControlSchemesView = CreateChildView(new ControlSchemesView(parent, stateContainer, updateExisting)); | ||
m_ControlSchemesView.UpdateView(stateContainer.GetState()); | ||
m_ControlSchemesView.OnClosing += _ => | ||
{ | ||
DestroyChildView(m_ControlSchemesView); | ||
m_ControlSchemesView = null; | ||
}; | ||
Check warning on line 260 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs
|
||
} | ||
|
||
private void SelectControlScheme(int controlSchemeIndex) | ||
|
@@ -258,6 +284,7 @@ | |
{ | ||
base.DestroyView(); | ||
s_OnPasteCutElements.Remove(this); | ||
Undo.undoRedoPerformed -= CheckForInvalidControlSchemeInOneFrame; | ||
} | ||
|
||
public void OnPaste(InputActionsEditorState state) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am misunderstanding this PR/issue so I want to check whether this problem is if you undo text editing while in text editing mode? Such editing should not have been applied yet to any serializedProperty right or am I misunderstanding this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit different than that, basically the last undo when opening a control scheme to edit is the creation of the asset.
Therefore undoing while editing the name actually deletes the asset.
This of course causes exceptions when inside the edit window if you try to alter the asset or even try to close it.
My solution I have landed on for now is to close the control scheme view when this happens and revert to selecting the all controls control scheme now instead.