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

[Bug]: Changing to certain modes in KryptonNavigator can cause a System.NullReferenceException #1580

Closed
Legingo opened this issue Jun 29, 2024 · 1 comment
Labels
area:designer All issues related to the designer. area:navigator All issues to do with the navigator. bug Something isn't working fixed This issue has been fixed. version:85-lts All things to do with V85 LTS.

Comments

@Legingo
Copy link

Legingo commented Jun 29, 2024

Describe the bug
Using KryptonNavigator and changing to either mode "Stack - CheckButton - HeaderGroup" or "Outlook - Full" will cause a
NullReferenceException.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Krypton\Standard-Toolkit-Demos\Source\Krypton Navigator Examples\Navigator Modes\Navigator Modes 2022.csproj
  2. Build and run
  3. Choose mode "Stack - CheckButton - HeaderGroup" (will cause NullReferenceException)
  4. Restart the program
  5. Choose mode "Outlook - Full" (will cause NullReferenceException)

Expected behavior
To work, no NullReferenceException.

Desktop:

  • OS: Windows 10 Pro
  • Version: Version 22H2
  • OS build: 19045.4412
  • Toolkit Version: 85.24.06.180

Tested against the following frameworks

  • Framework Version: 4.8
  • .Net Version: .Net6-windows
  • .Net Version: .Net7-windows

Additional context

Investigation of the "Stack - CheckButton - HeaderGroup" NullReferenceException.

Following the code with the debugger showed that you can legitimately end up
at the code below with _headerGroup set to null. Based on the comments in
the code that author was aware of this condition but forgot to add
a null reference check.

Krypton\Standard-Toolkit\Source\Krypton Components\Krypton.Navigator\View Builder\ViewBuilderStackCheckButtonHeaderGroup.cs
Line: 68

 public override void PageVisibleStateChanged(KryptonPage? page)
        {
            // If is possible the header group has not been created yet
            // Ensure buttons are recreated to reflect different previous/next visibility
            // _headerGroup.UpdateButtons();         <=== This needs to be changed
             _headerGroup?.UpdateButtons();          // Include embedded check for a null value

            // Let base class do standard work
            base.PageVisibleStateChanged(page);
        }

Investigation of the "Outlook - Full" NullReferenceException.
This one is a little bit more complicated that the previous bug.

Conceptually the "Outlook - Full" View is created then the Button
Manager is created (in this order due to interdependences between the Button Manager
and the View).

The view creation calls some overridden methods in the base class that eventually
lead to a call to UpdateButtons (but in the case of "Outlook - Full" the
Button Manager has yet be created) and boom!

Again the fix is simply a null reference check.

Krypton\Standard-Toolkit\Source\Krypton Components\Krypton.Navigator\View Builder\ViewletHeaderGroup.cs
Line: 118

  public void UpdateButtons() =>
            // Ensure buttons are recreated to reflect different page
            //_buttonManager?.RecreateButtons();      <=== This needs to be changed
            _buttonManager?.RecreateButtons();        // Include embedded check for a null value
@Legingo Legingo added the bug Something isn't working label Jun 29, 2024
@PWagner1
Copy link
Contributor

@Smurf-IV & @giduac

Although this is patched in V90, I'm going to apply a patch for V85.

cc. @Legingo

@PWagner1 PWagner1 self-assigned this Jun 29, 2024
@PWagner1 PWagner1 added under investigation This bug/issue is currently under investigation. area:navigator All issues to do with the navigator. version:85-lts All things to do with V85 LTS. area:designer All issues related to the designer. labels Jun 29, 2024
@PWagner1 PWagner1 added this to the Version 85 milestone Jun 30, 2024
PWagner1 added a commit that referenced this issue Jun 30, 2024
Smurf-IV added a commit that referenced this issue Jun 30, 2024
…ain-modes-in-kryptonnavigator-can-cause-a-systemnullreferenceexception

* Resolved #1580
@PWagner1 PWagner1 removed their assignment Jun 30, 2024
@PWagner1 PWagner1 added fixed This issue has been fixed. and removed under investigation This bug/issue is currently under investigation. labels Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:designer All issues related to the designer. area:navigator All issues to do with the navigator. bug Something isn't working fixed This issue has been fixed. version:85-lts All things to do with V85 LTS.
Projects
None yet
Development

No branches or pull requests

2 participants