Ckan: NullReferenceException in `_updateFilters()` on Windows

Created on 10 Jan 2019  路  9Comments  路  Source: KSP-CKAN/CKAN

Background

CKAN Version:
Current master (5434adb8cc9c73d5c599de1d0a33ec6ee2a768ca)
and earlier

KSP Version:
1.6.0

Operating System:
Windows

Have you made any manual changes to your GameData folder (i.e., not via CKAN)?

Problem

What steps did you take in CKAN?
Start it.

What did you expect to happen?
It should start without errors.

What happened instead?
Unhandled NullReferenceException is thrown.

CKAN error codes (if applicable):

System.NullReferenceException: Object reference not set to an instance of an object.
   at CKAN.Main._UpdateFilters()
   at CKAN.Util.Invoke[T](T obj, Action action)
   at CKAN.Main.UpdateFilters(Main control)
   at CKAN.Main.<.ctor>b__37_0(MainModList source)
   at CKAN.MainModList.set_ModFilter(GUIModFilter value)
   at CKAN.Main.Filter(GUIModFilter filter)
   at CKAN.Main.CurrentInstanceUpdated()
   at CKAN.Main.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

@politas already mentioned it earlier here.

Bug GUI

All 9 comments

I think this is a threading thing related to #2617.

Yeah it actually throws on line 109. I think _UpdateFilters() is called before _UpdateModsList() has completed, so mainModList.full_list_of_mod_rows is still null.

mainModList.full_list_of_mod_rows only gets set in mainModList.ConstructModList().
mainModList.ConstructModList() is only called in _UpdateModsList().
And that one seems to be too slow on some systems, so that _UpdateFilters() tries to access mainModList.full_list_of_mod_rows before it is set.

UpdateModsList() is called in CurrentInstanceUpdated(), like Filter() > UpdateFilters() (see stack trace).

And on some systems it can happen that Filter() and all the following code executes faster than UpdateFilters. There's the problem.

So I think the solution is to call Filter() not until ConstructModList() is called.
And that's where a knowledge in tasking and threading would come in handy.

Or you do it the dirty way and wait in a while loop until full_list_of_mod_rows isn't null anymore.

A simple null check might suffice, since UpdateModsList calls UpdateFilters at the end.

But what about the FilterToolButton.Text?

I'm adding the null check to UpdateFilters, not Filter, so it'll be set regardless.

Welp, yeah, not my brightest moment.

Was this page helpful?
0 / 5 - 0 ratings