Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Adding/Removing Ribbon tabs can cause NullReferenceException #185

Closed
jpatte opened this issue May 23, 2019 · 5 comments
Closed

Adding/Removing Ribbon tabs can cause NullReferenceException #185

jpatte opened this issue May 23, 2019 · 5 comments
Labels
done The issue has been solved fixed The issue has been fixed.

Comments

@jpatte
Copy link
Contributor

jpatte commented May 23, 2019

Hello,

We have an app that dynamically adds and removes ribbon tabs depending on the context. We have observed that a NullReferenceException in ViewDrawRibbonGroupsBorderSynch may cause the app to crash occasionally.

The problem is in ComponentFactory.Krypton.Ribbon\View Draw\ViewDrawRibbonGroupsBorderSynch.cs, line 72: the code checks if Ribbon.SelectedTab isn't null but, unlike all the other methods in the same source file, it omits to check if _tabToView has an entry for this tab. Simply adding this check fixes the issue.

I would gladly submit a pull request to fix this but I'm not sure which repository is used to maintain the source code.

Could you make this change?
Thanks!

Julien

@Wagnerp
Copy link
Collaborator

Wagnerp commented May 23, 2019

Hi @jpatte

Thank you for the message, this is the correct repository to pull requests to fix any issues that you find, as this is used for every other published version.

@Wagnerp Wagnerp added bug todo 🗒️ under investigation Investigation of bugs/issues labels May 23, 2019
@Wagnerp Wagnerp self-assigned this May 23, 2019
@Wagnerp
Copy link
Collaborator

Wagnerp commented May 23, 2019

Hi @jpatte

Is this what you mean?

 public ViewDrawRibbonGroup ViewGroupFromPoint(Point pt)
        {
            // There can only be groups showing for the currently selected tab
            if (Ribbon.SelectedTab != null && _tabToView != null)
            {
                // Get the scroll port for this tab
                ViewLayoutRibbonScrollPort viewScrollPort = _tabToView[Ribbon.SelectedTab];

                // The first child of the scroll port is always the view control
                ViewLayoutControl viewControl = viewScrollPort[0] as ViewLayoutControl;

                // The first child of the view control is always the ribbon groups
                ViewLayoutRibbonGroups viewGroups = viewControl.ChildView as ViewLayoutRibbonGroups;

                // Ask the view groups to find a matching group
                return viewGroups.ViewGroupFromPoint(pt);
            }

            return null;
        }

@jpatte
Copy link
Contributor Author

jpatte commented May 23, 2019

Hi, actually what I mean is:

public ViewDrawRibbonGroup ViewGroupFromPoint(Point pt)
        {
            // There can only be groups showing for the currently selected tab
            if((Ribbon.SelectedTab != null) &&
               (_tabToView.ContainsKey(Ribbon.SelectedTab)))
            {
                // Get the scroll port for this tab
                ViewLayoutRibbonScrollPort viewScrollPort = _tabToView[Ribbon.SelectedTab];

                // The first child of the scroll port is always the view control
                ViewLayoutControl viewControl = viewScrollPort[0] as ViewLayoutControl;

                // The first child of the view control is always the ribbon groups
                ViewLayoutRibbonGroups viewGroups = viewControl.ChildView as ViewLayoutRibbonGroups;

                // Ask the view groups to find a matching group
                return viewGroups.ViewGroupFromPoint(pt);
            }

            return null;
        }

We need to check if _tabToView contains an entry for Ribbon.SelectedTab otherwise _tabToView[Ribbon.SelectedTab] could throw an exception. That same check is already done in all the other methods of this class.

Thanks for letting me know about the repo, I'll submit pull requests if I stumble upon any other issue.

@Wagnerp
Copy link
Collaborator

Wagnerp commented May 24, 2019

Just added the fix, it'll be included in the next update.

Wagnerp added a commit that referenced this issue May 24, 2019
@jpatte
Copy link
Contributor Author

jpatte commented May 24, 2019

Great, thanks!

@Wagnerp Wagnerp added done The issue has been solved fixed The issue has been fixed. and removed bug todo 🗒️ under investigation Investigation of bugs/issues labels May 24, 2019
@Wagnerp Wagnerp removed their assignment May 24, 2019
@Wagnerp Wagnerp closed this as completed May 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
done The issue has been solved fixed The issue has been fixed.
Projects
None yet
Development

No branches or pull requests

2 participants