Skip to content

Commit

Permalink
fix: avatar selection change event bug causing null ref
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed Dec 29, 2024
1 parent dd40123 commit 45090c0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Editor/UI/Presenters/MainPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ private void UpdateView()
_view.SelectedAvatarIndex = 0;
}

if (oldIndex != _view.SelectedAvatarIndex)
if (oldIndex != -1 && oldIndex != _view.SelectedAvatarIndex)
{
_view.RaiseAvatarSelectionPopupChangeEvent();
_view.RaiseAvatarSelectionChangeEvent();
}

_view.ToolVersionText = UpdateChecker.CurrentVersion?.fullString;
Expand Down
3 changes: 2 additions & 1 deletion Editor/UI/Views/IMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal interface IMainView : IEditorView
event Action<PrefabStage> PrefabStageClosing;
event Action<PrefabStage> PrefabStageOpened;
event Action AvatarSelectionPopupChange;
event Action AvatarSelectionChange;

string UpdateAvailableFromVersion { get; set; }
string UpdateAvailableToVersion { get; set; }
Expand All @@ -50,6 +51,6 @@ internal interface IMainView : IEditorView
void ForceUpdateCabinetSubView();
void StartDressing(GameObject outfitGameObject = null, GameObject avatarGameObject = null);
void OpenUrl(string url);
void RaiseAvatarSelectionPopupChangeEvent();
void RaiseAvatarSelectionChangeEvent();
}
}
11 changes: 6 additions & 5 deletions Editor/UI/Views/MainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal class MainView : ElementView, IMainView
public event Action UpdateAvailableUpdateButtonClick;
public event Action MouseMove;
public event Action AvatarSelectionPopupChange;
public event Action AvatarSelectionChange;

public int SelectedAvatarIndex { get; set; }
public List<GameObject> AvailableAvatars { get; set; }
Expand Down Expand Up @@ -94,8 +95,8 @@ public MainView()
UpdateAvailableFromVersion = null;
UpdateAvailableToVersion = null;
ShowExitPlayModeHelpbox = false;
SelectedAvatarIndex = 0;
_lastSelectedAvatarIndex = 0;
SelectedAvatarIndex = -1;
_lastSelectedAvatarIndex = -1;
AvailableAvatars = new List<GameObject>();
}

Expand Down Expand Up @@ -272,11 +273,11 @@ private void RepaintAvatarSelection()
_avatarSelectionPopupContainer.Add(_avatarSelectionPopup);

// force update avatar subview if the selected index has changed
if (_lastSelectedAvatarIndex != SelectedAvatarIndex)
if (_lastSelectedAvatarIndex != -1 && _lastSelectedAvatarIndex != SelectedAvatarIndex)
{
_lastSelectedAvatarIndex = SelectedAvatarIndex;
_avatarSubView.RaiseForceUpdateViewEvent();
}
_lastSelectedAvatarIndex = SelectedAvatarIndex;
}

private void RepaintDebugInfo()
Expand All @@ -294,6 +295,6 @@ public override void Repaint()
RepaintDebugInfo();
}

public void RaiseAvatarSelectionPopupChangeEvent() => AvatarSelectionPopupChange?.Invoke();
public void RaiseAvatarSelectionChangeEvent() => AvatarSelectionChange?.Invoke();
}
}
2 changes: 1 addition & 1 deletion Editor/UI/Views/OneConfDressSubView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class OneConfDressSubView : ElementView, IOneConfDressSubView, IOneConf
{
private static readonly I18nTranslator t = I18n.ToolTranslator;

public event Action TargetAvatarChange { add => _mainView.AvatarSelectionPopupChange += value; remove => _mainView.AvatarSelectionPopupChange -= value; }
public event Action TargetAvatarChange { add => _mainView.AvatarSelectionChange += value; remove => _mainView.AvatarSelectionChange -= value; }
public event Action TargetWearableChange;
public event Action AddToCabinetButtonClick;
public GameObject TargetAvatar { get => _mainView.SelectedAvatarGameObject; }
Expand Down

0 comments on commit 45090c0

Please sign in to comment.