Skip to content
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

fix: NRE if the window exists in background #226

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- NullReferenceException if window is in background `#226`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- NullReferenceException if window is in background `#226`

### Security

Expand Down
15 changes: 10 additions & 5 deletions Internal/ErrorReporter/Editor/ErrorReportUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using Debug = System.Diagnostics.Debug;

namespace Anatawa12.AvatarOptimizer.ErrorReporting
{
Expand All @@ -25,7 +26,8 @@ public static void OpenErrorReportUIFor(AvatarReport avatar)
{
var window = GetWindow<ErrorReportUI>();
window.Show();
window._header.Value = avatar;
if (window._header != null)
window._header.Value = avatar;
}

public static void MaybeOpenErrorReportUI()
Expand Down Expand Up @@ -60,9 +62,9 @@ private void OnDisable()
}

private const int RefreshDelayTime = 500;
private Stopwatch _delayTimer;
private HeaderBox _header;
private GameObject _defaultAvatarObject;
[CanBeNull] private Stopwatch _delayTimer;
[CanBeNull] private HeaderBox _header;
[CanBeNull] private GameObject _defaultAvatarObject;

private void ScheduleRender()
{
Expand All @@ -79,6 +81,7 @@ private void ScheduleRender()

private async void StartRenderTimer()
{
Debug.Assert(_delayTimer != null, nameof(_delayTimer) + " != null");
while (_delayTimer.ElapsedMilliseconds < RefreshDelayTime)
{
long remaining = RefreshDelayTime - _delayTimer.ElapsedMilliseconds;
Expand Down Expand Up @@ -140,6 +143,7 @@ private void CreateGUI()

private void UpdateErrorList(VisualElement box, [NotNull] AvatarReport activeAvatar)
{
Debug.Assert(_header != null, nameof(_header) + " != null");
var activeAvatarObject = activeAvatar == _header.DefaultValue ? _defaultAvatarObject : null;
var lookupCache = new ObjectRefLookupCache();
var avBox = new Box();
Expand Down Expand Up @@ -181,7 +185,8 @@ private void RenderContent()
{
var (activeAvatar, activeAvatarObject) = GetDefaultAvatar();
_defaultAvatarObject = activeAvatarObject;
_header.DefaultValue = activeAvatar;
if (_header != null)
_header.DefaultValue = activeAvatar;
}
}

Expand Down