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 on purging cache in GUI #3810

Merged
merged 1 commit into from Apr 19, 2023

Conversation

HebaruSan
Copy link
Member

Problem

If you use the purge all option in the GUI settings, an exception is thrown:

image

Causes

  • The Contents tab has a poor public interface, with two ways to change the active mod, the SelectedModule property and UpdateModContentsTree
  • UpdateModContentsTree has a module parameter, which is malsuited to this function's usage, which is simply to refresh the currently displayed mod after caching or purging, which requires calling code to do unnecessary work to retrieve and pass the currently shown mod
  • UpdateModContentsTree assumes that its CkanModule parameter will never be null
  • SettingsDialog passes that parameter as null after purging, to try to refresh the display in case a previously cached mod is shown, because it seemed like a natural way to request an operation on the same mod

Changes

  • Now the public interface of the Contents tab has only SelectedModule for setting the mod, and UpdateModContentsTree is replaced by a new Refresh function for refreshing, which importantly does not have a module parameter and only re-uses the currently displayed one
  • Similarly Main.UpdateModContentsTree and ModInfo.UpdateModContentsTree are replaced by zero-parameter functions Main.RefreshModContentsTree and ModInfo.RefreshModContentsTree calling Contents.Refresh
  • Now all usages of UpdateModContentsTree are replaced by calls to Refresh, which eliminates the possibility of a null reference exception

Fixes #3809.

@GreenKeldeo, a few minutes after this is submitted, assuming there are no compile errors or failed tests, there should be a test build here under the Artifacts dropdown of the Contents tab, if you'd like try out the fix.

@HebaruSan HebaruSan added Bug Easy This is easy to fix GUI Issues affecting the interactive GUI Pull request labels Mar 11, 2023
Copy link
Member

@techman83 techman83 left a comment

Choose a reason for hiding this comment

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

Sensible improvement, thanks @HebaruSan !

@HebaruSan HebaruSan merged commit d9a68dc into KSP-CKAN:master Apr 19, 2023
12 checks passed
@HebaruSan HebaruSan deleted the fix/purge-cache-nre branch May 11, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Easy This is easy to fix GUI Issues affecting the interactive GUI Pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] NRE thrown on purge all cache files
2 participants