Skip to content

Conversation

@graham-huws
Copy link
Collaborator

@graham-huws graham-huws commented Jan 30, 2024

Description

It's possible for RedrawUI to be called when m_Root is empty, throwing errors in the console.
This can happen when the view is discarded immediately after being loaded, i.e. jumping to the input settings
page in Preferences when the last window shown there was the main view, which the editor (briefly) loads first. (ISX-1721)

Changes made

Compare against the number of m_ChildViews as a cheap way to know we should skip redrawing.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

@graham-huws graham-huws force-pushed the ISX-1721-settings-error-in-console branch from 3d9af80 to 762b5aa Compare January 30, 2024 15:48
@graham-huws graham-huws requested a review from ekcoh January 30, 2024 15:50
@graham-huws graham-huws marked this pull request as ready for review January 30, 2024 15:50
@graham-huws
Copy link
Collaborator Author

graham-huws commented Jan 30, 2024

@ekcoh - I don't think this fix is "ideal", but it's a small change and it's a very specific set of circumstances required to make the errors occur, and this catches that. If you've got any thoughts on improving though, I'm interested!

If there's a way to check for children by name in m_Root that doesn't produce errors, that's probably better 🤔

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing this fix. I think it can be improved by moving all of it into ViewBase#UpdateView method.

private readonly TreeView m_ActionsTreeView;
private Button addActionButton => m_Root?.Q<Button>("add-new-action-button");
private readonly Button m_AddActionButton;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ritamerkl, is moving addActionButton around here okay? I wasn't sure why it was set up differently to eg. m_ActionsTreeView. I made the change because otherwise it seemed to be accessing the root too early when following the repro steps for the bug which this PR fixes. ("Expected a visual element called 'add-new-action-button' of type 'UnityEngine.UIElements.Button' to exist but none was found.")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me the change makes sense but would be good to get info from @ritamerkl whether there was any reason to do this lazily via getter indirection. If not I propose we look it up once and case it as a readonly var as suggested by @graham-huws.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me!

@graham-huws graham-huws requested a review from ekcoh February 1, 2024 11:04
Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tried opening/editing different settings assets both active and inactive ones and wasn't able to repro the error anymore.

}

private Button addActionMapButton => m_Root?.Q<Button>("add-new-action-map-button");
private Button addActionMapButton => rootElement?.Q<Button>("add-new-action-map-button");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for querying this lazily? If not I would advise initializing the reference as readonly in the constructor using the passed root argument instead of querying it on each call.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now its adressed differently in ActionMapsView vs ActionPropertiesView.

private readonly TreeView m_ActionsTreeView;
private Button addActionButton => m_Root?.Q<Button>("add-new-action-button");
private readonly Button m_AddActionButton;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me the change makes sense but would be good to get info from @ritamerkl whether there was any reason to do this lazily via getter indirection. If not I propose we look it up once and case it as a readonly var as suggested by @graham-huws.

m_Root = root;

m_ListView = m_Root?.Q<ListView>("action-maps-list-view");
m_ListView = rootElement?.Q<ListView>("action-maps-list-view");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use rootElement when you already have root passed as arg?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pattern in all the constructors. It probably doesn't matter at the moment but if accessing base within constructor (while constructing the object) can be avoided its usually good to avoid. (This exists in all affected classes but haven't commented on all of them).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pattern in all the constructors. It probably doesn't matter at the moment but if accessing base within constructor (while constructing the object) can be avoided its usually good to avoid.

Interesting, is that a style thing? I assumed performance-wise it would be the same; my thinking was that it's better to have everything accessing rootElement since then it's consistent across the files (eg. it's more clear that the root in the constructor and in RedrawUI is the same). Happy to change, either way!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its probably just in the category nit-picking and could be ignored, but since there is already a local (potentially) in a register, why call into a getter that needs to fetch the reference from base?

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see the difference from when I last checked, lgtm

@graham-huws graham-huws merged commit e58f599 into develop Feb 2, 2024
@graham-huws graham-huws deleted the ISX-1721-settings-error-in-console branch February 2, 2024 09:45
@Pauliusd01 Pauliusd01 restored the ISX-1721-settings-error-in-console branch February 2, 2024 14:31
@Pauliusd01 Pauliusd01 deleted the ISX-1721-settings-error-in-console branch February 2, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants